Skip to content

Commit dafd1c0

Browse files
authored
Merge pull request #194 from bytestream/anchor-target-query-param
fix: query parameter parsed as character entity
2 parents 6b47f1f + 475f5f5 commit dafd1c0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/HTML5/Parser/Tokenizer.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,16 +1181,11 @@ protected function decodeCharacterReference($inAttribute = false)
11811181
return $entity;
11821182
}
11831183

1184-
// If in an attribute, then failing to match ; means unconsume the
1185-
// entire string. Otherwise, failure to match is an error.
1186-
if ($inAttribute) {
1187-
$this->scanner->unconsume($this->scanner->position() - $start);
1188-
1189-
return '&';
1190-
}
1184+
// Failing to match ; means unconsume the entire string.
1185+
$this->scanner->unconsume($this->scanner->position() - $start);
11911186

11921187
$this->parseError('Expected &ENTITY;, got &ENTITY%s (no trailing ;) ', $tok);
11931188

1194-
return '&' . $entity;
1189+
return '&';
11951190
}
11961191
}

test/HTML5/Html5Test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,13 @@ public function testCDATA()
480480
$res = $this->cycleFragment('a<![CDATA[ This <is> a test. ]]>b');
481481
$this->assertRegExp('|<!\[CDATA\[ This <is> a test\. \]\]>|', $res);
482482
}
483+
484+
public function testAnchorTargetQueryParam()
485+
{
486+
$res = $this->cycle('<a href="https://domain.com/page.php?foo=bar&target=baz">https://domain.com/page.php?foo=bar&target=baz</a>');
487+
$this->assertContains(
488+
'<a href="https://domain.com/page.php?foo=bar&amp;target=baz">https://domain.com/page.php?foo=bar&amp;target=baz</a>',
489+
$res
490+
);
491+
}
483492
}

0 commit comments

Comments
 (0)