@@ -122,3 +122,45 @@ def test_replace_skip_location(self):
122122 "law. </dfn> state law. <dfn> <a href=\" link_url\" >state"
123123 "</a> liability. </dfn>" )
124124 self .assertEquals (applier .text , result )
125+
126+ def test_apply_layers (self ):
127+ # Tests same as above but from one level out.
128+ original = 'state'
129+ replacement = '<a href="link_url">state</a>'
130+ locations = [0 , 2 ]
131+ text = ("<em>(6)</em> <dfn> Under state law. </dfn> state "
132+ "law. <dfn> state liability. </dfn>" )
133+
134+ applier = layers_applier .LayersApplier ()
135+ applier .enqueue ((original , replacement , locations ))
136+ applier .apply_layers (text )
137+
138+ result = ("<em>(6)</em> <dfn> Under <a href=\" link_url\" >state</a> "
139+ "law. </dfn> state law. <dfn> <a href=\" link_url\" >state"
140+ "</a> liability. </dfn>" )
141+ self .assertEquals (applier .text , result )
142+
143+ def test_apply_layers_escaping (self ):
144+ # See https://github.com/eregs/regulations-site/issues/514 and
145+ # https://github.com/fecgov/fec-eregs/issues/382
146+ #
147+ # It appears that we had a holdover step of unescaping that, thanks to
148+ # looser interpretations in Python 3.6 (specifically, ``&sec`` was
149+ # treated as a valid escape even without a trailing semicolon) started
150+ # breaking links that have a ``§ion`` parameter.
151+ original = 'state'
152+ replacement = '<a href="link_url">state</a>'
153+ locations = [0 , 2 ]
154+ text = ("<em>(6)</em> <dfn> Under state law. </dfn> state "
155+ "law. <dfn> state liability. </dfn>"
156+ "<a href='http://example.org?one=1§ion2'>test</a>" )
157+
158+ applier = layers_applier .LayersApplier ()
159+ applier .enqueue ((original , replacement , locations ))
160+ applier .apply_layers (text )
161+
162+ result = ("<em>(6)</em> <dfn> Under <a href=\" link_url\" >state</a> "
163+ "law. </dfn> state law. <dfn> <a href=\" link_url\" >state"
164+ "</a> liability. </dfn>"
165+ "<a href='http://example.org?one=1§ion2'>test</a>" )
166+ self .assertEquals (applier .text , result )
0 commit comments