Skip to content

Commit 4c19af4

Browse files
committed
Rename the tag handling unit test
1 parent a4ffcc2 commit 4c19af4

1 file changed

Lines changed: 58 additions & 29 deletions

File tree

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
11
"""
2-
Tests for two related br/hr fixes:
3-
4-
1. Missing-trailing-slash matching (selfClosing_tag_patterns /
5-
lineBreak_tag_patterns): old-style HTML4 syntax like <br clear=all>
6-
(no trailing slash) previously never matched at all, surviving into
7-
extracted text HTML-escaped as literal "&lt;br clear=all&gt;". A
8-
bare <br> with no attributes had exactly the same problem.
9-
10-
2. Word-merging on deletion (this file's main focus): even where a
11-
br/hr tag WAS correctly matched, it was deleted with nothing
12-
substituted in its place (dropSpans() just concatenates the text on
13-
either side of a removed span). If there was no surrounding
14-
whitespace in the source -- a real, confirmed case on Saraiki
15-
Wikipedia, "اُٹھا<br>رب" with no spaces at all around the tag --
16-
deleting it merges two separate words into one ("اُٹھارب").
17-
18-
The fix: br/hr are pulled out into their own lineBreakTags group,
19-
matched with the same permissive (optional trailing slash) pattern as
20-
before, but substituted with a single space instead of being folded
21-
into the generic drop-with-nothing spans mechanism.
22-
23-
nobr/ref/references/nowiki are NOT affected by the space-substitution
24-
part of this fix (see RefTagSafetyTests / NobrTagTests below):
25-
"no line break" doesn't call for inserting a space where the tag was,
26-
and ref's self-closing form has a distinct, real meaning from its
27-
paired form (see test_br_tag_handling's sibling investigation) that
28-
must not be disturbed.
2+
Tests for self-closing/void-element tag handling in extract.py:
3+
br, hr, nobr, ref, references, nowiki, templatestyles. All of these
4+
share the same underlying mechanism (selfClosingTags/lineBreakTags,
5+
selfClosing_tag_patterns/lineBreak_tag_patterns, and the shared
6+
tag-processing loop in clean()), which is why they're tested together
7+
here rather than split across files -- a change to that shared
8+
mechanism (as several of the fixes below were) has to be checked
9+
against all of them at once anyway.
10+
11+
Fixes covered:
12+
13+
1. Missing-trailing-slash matching: old-style HTML4 syntax like
14+
<br clear=all> (no trailing slash) previously never matched at
15+
all for br/hr/nobr, surviving into extracted text HTML-escaped as
16+
literal "&lt;br clear=all&gt;". A bare <br> with no attributes had
17+
exactly the same problem.
18+
19+
2. Word-merging on deletion (br/hr specifically): even where a br/hr
20+
tag WAS correctly matched, it was deleted with nothing substituted
21+
in its place (dropSpans() just concatenates the text on either
22+
side of a removed span). If there was no surrounding whitespace in
23+
the source -- a real, confirmed case on Saraiki Wikipedia,
24+
"اُٹھا<br>رب" with no spaces at all around the tag -- deleting it
25+
merges two separate words into one ("اُٹھارب"). Fixed by
26+
substituting a space instead of deleting outright.
27+
28+
3. Boundary-awareness (br/hr specifically): the space-substitution
29+
fix above should not add a space when the tag sits at the start/end
30+
of a line -- there's nothing on the empty side to merge with, and
31+
doing so anyway creates an invisible leading/trailing space that
32+
clutters diffs without affecting meaning (a real large diff on
33+
Saraiki Wikipedia showed many lines as "changed" while looking
34+
completely identical, for exactly this reason). Checking for ANY
35+
adjacent whitespace (not just newline) also matters here: without
36+
it, the substitution function isn't self-sufficient and can
37+
produce a double space on its own when the source already had one
38+
space adjacent to the tag.
39+
40+
4. templatestyles (a real MediaWiki extension tag that loads CSS
41+
styling for a template's rendering -- pure presentational
42+
metadata, never wraps real article prose) was previously
43+
unhandled entirely and survived into extracted text HTML-escaped,
44+
e.g. "&lt;templatestyles src=\"حوالے/styles.css\" /&gt;". Added to
45+
selfClosingTags for pure deletion (no useful content to preserve,
46+
and no space-substitution justification the way br/hr have).
47+
48+
Critically, ref/references/nowiki deliberately keep the strict
49+
"slash required" matching pattern: for ref specifically, the
50+
self-closing form has a real, distinct meaning (e.g. <ref name="x" />
51+
reuses an earlier-defined reference) from the non-self-closing form
52+
(<ref name="x">actual citation text</ref>, a genuine paired tag with
53+
real content) -- making the slash optional for these would
54+
misidentify the OPENING of a real paired tag as if it were
55+
self-closing. This was verified directly: doing so naively DOES cause
56+
a real paired ref tag's opening to falsely match. See
57+
RefTagSafetyTests.
2958
3059
Run with:
31-
python -m unittest tests.test_br_tag_handling -v
60+
python -m unittest tests.test_selfclosing_tags -v
3261
or, from the tests/ directory:
33-
python -m unittest test_br_tag_handling -v
62+
python -m unittest test_selfclosing_tags -v
3463
"""
3564

3665
import sys

0 commit comments

Comments
 (0)