Subramanya Sastry has uploaded a new change for review. https://gerrit.wikimedia.org/r/179908
Change subject: Improvements to full-nowiki wrapping in a quote context ...................................................................... Improvements to full-nowiki wrapping in a quote context * When there are non-quote escapable characters in a string, verify that they actually need escaping before doing a full nowiki wrap. * Fixes nowiki wrapping issues like this: http://parsoid-tests.wikimedia.org/resultFlagNew/0554e63c5c90ff3d799f7a3990b534fd9e79787d/56cd9926b3ddd38c7670810671ff957bc4e35298/frwiki/T%C3%A9m%C3%A9raire_%28fantasy%29 * Updated existing parser test to capture this expectation. Change-Id: Ib4d3f0c88b1836d4247546d013cf9276b2676fb9 --- M lib/wts.escapeWikitext.js M tests/parserTests-blacklist.js M tests/parserTests.txt 3 files changed, 22 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/08/179908/1 diff --git a/lib/wts.escapeWikitext.js b/lib/wts.escapeWikitext.js index 6c0c68f..f90a155 100644 --- a/lib/wts.escapeWikitext.js +++ b/lib/wts.escapeWikitext.js @@ -533,21 +533,27 @@ return this.escapedText(state, false, text, true); } - // Full-wrapping <nowiki>..</nowiki> scenario for quotes - if ((fullCheckNeeded || hasNonQuoteEscapableChars || indentPreUnsafe) && - (/''+/.test(text) + // Quote-escape test + if (/''+/.test(text) || hasLeadingEscapableQuoteChar(text, opts) - || hasTrailingEscapableQuoteChar(text, opts))) + || hasTrailingEscapableQuoteChar(text, opts)) { - state.env.log("trace/wt-escape", "---quotes: full nowiki wrap---"); - return this.escapedText(state, false, text, true); - } - - // Selective <nowiki/> escaping for quotes - var quoteEscapedText = escapedIBSiblingNodeText(text, opts); - if (quoteEscapedText) { - state.env.log("trace/wt-escape", "---sibling of i/b tag---"); - return quoteEscapedText; + // Check if we need full-wrapping <nowiki>..</nowiki> + // or selective <nowiki/> escaping for quotes. + if (fullCheckNeeded + || indentPreUnsafe + || (hasNonQuoteEscapableChars && + this.hasWikitextTokens(state, sol, this.serializer.options, text))) + { + state.env.log("trace/wt-escape", "---quotes: full nowiki wrap---"); + return this.escapedText(state, false, text, true); + } else { + var quoteEscapedText = escapedIBSiblingNodeText(text, opts); + if (quoteEscapedText) { + state.env.log("trace/wt-escape", "---sibling of i/b tag---"); + return quoteEscapedText; + } + } } // Template and template-arg markers are escaped unconditionally! diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js index 80d1462..2922ee0 100644 --- a/tests/parserTests-blacklist.js +++ b/tests/parserTests-blacklist.js @@ -1200,7 +1200,7 @@ add("html2wt", "Magic Word: {{SUBJECTPAGENAMEE}}", "User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason\n"); add("html2wt", "Magic Word: {{NUMBEROFFILES}}", "5\n"); add("html2wt", "Magic Word: {{PAGENAME}}", "Ævar Arnfjörð Bjarmason\n"); -add("html2wt", "Magic Word: {{PAGENAME}} with metacharacters", "''<nowiki>'foo & bar = baz'</nowiki>''\n"); +add("html2wt", "Magic Word: {{PAGENAME}} with metacharacters", "''<nowiki/>'foo & bar = baz'<nowiki/>''\n"); add("html2wt", "Magic Word: {{PAGENAME}} with metacharacters (bug 26781)", "<nowiki>*RFC 1234 http://example.com/</nowiki>\n"); add("html2wt", "Magic Word: {{PAGENAMEE}}", "%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason\n"); add("html2wt", "Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781)", "<nowiki>*RFC_1234_http://example.com/</nowiki>\n"); diff --git a/tests/parserTests.txt b/tests/parserTests.txt index d0c7ed7..cdf0987 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -20795,6 +20795,7 @@ '<nowiki/>'''foo'''<nowiki/>' ''fools'<span> errand</span>'' ''<span>fool</span>'s errand'' +a|!*#-:;+-~[]{}<>b'<nowiki/>''x'' !! html/* <p><i>'foo'</i> <i>''foo''</i> @@ -20813,6 +20814,7 @@ '<b>foo</b>' <i>fools'<span> errand</span></i> <i><span>fool</span>'s errand</i> +a|!*#-:;+-~[]{}<>b'<i>x</i> </p> !! end -- To view, visit https://gerrit.wikimedia.org/r/179908 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib4d3f0c88b1836d4247546d013cf9276b2676fb9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
