Skip to content

Commit

Permalink
Merge pull request #194 from bytestream/anchor-target-query-param
Browse files Browse the repository at this point in the history
fix: query parameter parsed as character entity
  • Loading branch information
goetas authored Sep 1, 2020
2 parents 6b47f1f + 475f5f5 commit dafd1c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/HTML5/Parser/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,16 +1181,11 @@ protected function decodeCharacterReference($inAttribute = false)
return $entity;
}

// If in an attribute, then failing to match ; means unconsume the
// entire string. Otherwise, failure to match is an error.
if ($inAttribute) {
$this->scanner->unconsume($this->scanner->position() - $start);

return '&';
}
// Failing to match ; means unconsume the entire string.
$this->scanner->unconsume($this->scanner->position() - $start);

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

return '&' . $entity;
return '&';
}
}
9 changes: 9 additions & 0 deletions test/HTML5/Html5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,13 @@ public function testCDATA()
$res = $this->cycleFragment('a<![CDATA[ This <is> a test. ]]>b');
$this->assertRegExp('|<!\[CDATA\[ This <is> a test\. \]\]>|', $res);
}

public function testAnchorTargetQueryParam()
{
$res = $this->cycle('<a href="https://domain.com/page.php?foo=bar&target=baz">https://domain.com/page.php?foo=bar&target=baz</a>');
$this->assertContains(
'<a href="https://domain.com/page.php?foo=bar&amp;target=baz">https://domain.com/page.php?foo=bar&amp;target=baz</a>',
$res
);
}
}

0 comments on commit dafd1c0

Please sign in to comment.