Skip to content

Commit 23b4e36

Browse files
committed
Allow consecutive question marks in inline processing instructions
1 parent d764452 commit 23b4e36

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎commonmark/src/main/java/org/commonmark/internal/inline/HtmlInlineParser.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,13 @@ private boolean tryProcessingInstruction(Scanner scanner) {
164164
return false;
165165
}
166166
scanner.next();
167-
int found;
168-
while ((found = scanner.find('?')) > 0) {
167+
while (scanner.find('?') >= 0) {
169168
scanner.next();
170169
if (scanner.next('>')) {
171170
return true;
172171
}
173172
}
174-
// The loop also ends when a `?` is found directly at the current position (`found == 0`),
175-
// which is not the end of the input, so only remember the miss when the scan really did
176-
// reach the end.
177-
noProcessingInstructionEnd = found < 0;
173+
noProcessingInstructionEnd = true;
178174
return false;
179175
}
180176

‎commonmark/src/test/java/org/commonmark/test/HtmlInlineParserTest.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ public void cdata() {
2121
assertRendering("inline <![CDATA[ ] ]] ]]>", "<p>inline <![CDATA[ ] ]] ]]></p>\n");
2222
}
2323

24+
@Test
25+
public void processingInstruction() {
26+
assertRendering("inline <??>", "<p>inline <??></p>\n");
27+
assertRendering("inline <?a??>", "<p>inline <?a??></p>\n");
28+
assertRendering("inline <?? <?php ?>", "<p>inline <?? <?php ?></p>\n");
29+
}
30+
2431
@Test
2532
public void afterFailedAttempt() {
2633
// A `<` that doesn't start inline HTML must not stop a later one from being parsed
2734
assertRendering("inline <!- <!-- a -->", "<p>inline &lt;!- <!-- a --></p>\n");
28-
assertRendering("inline <?? <?php ?>", "<p>inline &lt;?? <?php ?></p>\n");
2935
assertRendering(
3036
"inline <![x]]> <![CDATA[a]]>", "<p>inline &lt;![x]]&gt; <![CDATA[a]]></p>\n");
3137
assertRendering("inline <!foo> <!bar baz>", "<p>inline &lt;!foo&gt; <!bar baz></p>\n");

0 commit comments

Comments
 (0)