Skip to content

Commit ebc77fa

Browse files
committed
XRENDERING-765: HTML parsing error on saving attempt page that has empty line at the start of the link
* Make HTML parsing more robust by ignoring stray stopmacro and stopwikilink comments instead of failing to parse. (cherry picked from commit 0a8726f)
1 parent 3acd4a9 commit ebc77fa

File tree

2 files changed

+60
-0
lines changed
  • xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src

2 files changed

+60
-0
lines changed

xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/parser/xhtml/wikimodel/XWikiCommentHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ private void handleLinkCommentStart(String content, TagStack stack)
234234

235235
private void handleLinkCommentStop(TagStack stack)
236236
{
237+
// If there's no active link listener, it means we received a stopwikilink outside a link context
238+
// (e.g., duplicated by the browser while fixing malformed HTML). In that case, ignore it.
239+
if (stack.getStackParameter(LINK_LISTENER) == null) {
240+
return;
241+
}
242+
237243
XWikiGeneratorListener xwikiListener =
238244
(XWikiGeneratorListener) stack.popStackParameter(LINK_LISTENER);
239245
XDOMGeneratorListener linkLabelRenderer = (XDOMGeneratorListener) xwikiListener.getListener();
@@ -269,6 +275,11 @@ private void handleImageCommentStart(String content, TagStack stack)
269275

270276
private void handleImageCommentStop(TagStack stack)
271277
{
278+
// Ignore stray stopimage if there's no image context.
279+
if (!Boolean.TRUE.equals(stack.getStackParameter(IS_IN_IMAGE))) {
280+
return;
281+
}
282+
272283
boolean isFreeStandingImage = (Boolean) stack.getStackParameter(IS_FREE_STANDING_IMAGE);
273284

274285
ResourceReference imageReference =
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.#-----------------------------------------------------
2+
.input|xhtml/1.0
3+
.# Stray stopmacro and stopwikilink comments
4+
.#-----------------------------------------------------
5+
<p><!--startwikilink:false|-|url|-|https://www.xwiki.org/xwiki/bin/view/Main/--><span class="wikiexternallink"><a
6+
href="https://www.xwiki.org/xwiki/bin/view/Main/"><!--startmacro:info|-||-|Type your information message here.--><!--stopmacro--></a></span><!--stopwikilink--></p><div
7+
class="box infomessage"><a href="https://www.xwiki.org/xwiki/bin/view/Main/"><span class="sr-only">Information</span></a><p><a
8+
href="https://www.xwiki.org/xwiki/bin/view/Main/"><span data-xwiki-non-generated-content="java.util.List&lt;org.xwiki.rendering.block.Block&gt;"
9+
class="xwiki-metadata-container">Type your information message here.</span></a></p></div><!--stopmacro--><!--stopwikilink--><p>&nbsp;</p>
10+
.#-----------------------------------------------------
11+
.expect|event/1.0
12+
.#-----------------------------------------------------
13+
beginDocument
14+
beginParagraph
15+
beginLink [Typed = [false] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
16+
onMacroInline [info] [] [Type your information message here.]
17+
endLink [Typed = [false] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
18+
endParagraph
19+
beginGroup [[class]=[box infomessage]]
20+
beginParagraph
21+
beginLink [Typed = [true] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
22+
beginFormat [NONE] [[class]=[sr-only]]
23+
onWord [Information]
24+
endFormat [NONE] [[class]=[sr-only]]
25+
endLink [Typed = [true] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
26+
beginLink [Typed = [true] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
27+
beginMetaData [[non-generated-content]=[java.util.List<org.xwiki.rendering.block.Block>]]
28+
onWord [Type]
29+
onSpace
30+
onWord [your]
31+
onSpace
32+
onWord [information]
33+
onSpace
34+
onWord [message]
35+
onSpace
36+
onWord [here]
37+
onSpecialSymbol [.]
38+
endMetaData [[non-generated-content]=[java.util.List<org.xwiki.rendering.block.Block>]]
39+
endLink [Typed = [true] Type = [url] Reference = [https://www.xwiki.org/xwiki/bin/view/Main/]] [false]
40+
endParagraph
41+
endGroup [[class]=[box infomessage]]
42+
beginParagraph
43+
onSpace
44+
endParagraph
45+
endDocument
46+
.#-----------------------------------------------------
47+
.expect|xhtml/1.0
48+
.#-----------------------------------------------------
49+
<p><span class="wikiexternallink"><a href="https://www.xwiki.org/xwiki/bin/view/Main/"></a></span></p><div class="box infomessage"><p><span class="wikiexternallink"><a href="https://www.xwiki.org/xwiki/bin/view/Main/"><span class="sr-only">Information</span></a></span><span class="wikiexternallink"><a href="https://www.xwiki.org/xwiki/bin/view/Main/">Type your information message here.</a></span></p></div><p>&nbsp;</p>

0 commit comments

Comments
 (0)