GWicke has uploaded a new change for review.
https://gerrit.wikimedia.org/r/101341
Change subject: Bug 58054: Implement URL link parenthesis heuristic
......................................................................
Bug 58054: Implement URL link parenthesis heuristic
Change-Id: Ib09009dd5be74f78bdfcf784f734c9e1067667ea
---
M js/lib/pegTokenizer.pegjs.txt
M js/tests/parserTests-blacklist.js
M js/tests/parserTests.txt
3 files changed, 83 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/41/101341/1
diff --git a/js/lib/pegTokenizer.pegjs.txt b/js/lib/pegTokenizer.pegjs.txt
index 759bd82..898d581 100644
--- a/js/lib/pegTokenizer.pegjs.txt
+++ b/js/lib/pegTokenizer.pegjs.txt
@@ -801,7 +801,21 @@
urllink
= target:url {
- return [ new SelfclosingTagTk( 'urllink', [new KV('href', target)], {
tsr: [pos0, pos] } ) ];
+ // Special case handling for trailing parentheses: remove from link if
+ // there is no opening parenthesis in the link
+ var unmatchedParenthesis = '';
+ if (!/[(]/.test(target) && /[)]$/.test(target)) {
+ target = target.substr(0, target.length - 1);
+ unmatchedParenthesis = ')';
+ pos--;
+ }
+
+ var res = [ new SelfclosingTagTk( 'urllink', [new KV('href', target)], {
tsr: [pos0, pos] } ) ];
+ //if (unmatchedParenthesis) {
+ // // convert the parenthesis back to text
+ // res.push(unmatchedParenthesis);
+ //}
+ return res;
}
extlink
diff --git a/js/tests/parserTests-blacklist.js
b/js/tests/parserTests-blacklist.js
index 95c44e9..413477a 100644
--- a/js/tests/parserTests-blacklist.js
+++ b/js/tests/parserTests-blacklist.js
@@ -2587,6 +2587,10 @@
add("selser", "Parsoid:External link containing double-single-quotes with no
space separating the url from text in italics [[2,2,[3]]]",
"e4b0cr5e5hebqpvi[http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm''La
muerte de Casagemas'' (1901) en el sitio de [[Museo Picasso (ParĂs)|Museo
Picasso]].]tmotz4w6fiwtrzfr<span></span>\n");
add("selser", "Brackets in urls [2,4,0]",
"jt3mhqkqq3ibpgb9\n\nhttp://example.com/index.php?foozoid%5B%5D=barglg4gwwgnd1pds4i\nhttp://example.com/index.php?foozoid[]=bar");
add("selser", "Non-extlinks in brackets
[[2,0,0,[4],3,1,3,4,0,[4],3,3,0,0,0,4,4,3,0]]", "yr15z13xwdtgwrk9[foo]\n[foo
bar]\n[foo ''bar'']\n[fool's] errand\n[fool's
errand]\n[{{echo|foo}}{{echo|foo}}wygre0z954qp8pvi ''i6es9gp5lxcrf6r'''s]
errand\n[{{echo|foo}}l's errand]\n[2zx5a0zqruihehfrbg64um1261e2ke29]");
+add("selser", "Parenthesis in external links, especially URL links (Parsoid)
[0,4,[[2],0],2,3,3,4,3,[2,4],4,2,3,[1],3,[4]]",
"http://example.com)h0kohrrl2bl9dx6r\n[http://example.com/test
u0ani4jojnp9o1orhttp://example.com/test])64cs2wpwdd9uow29\n\njgvty1nl2p47k3xr\n\n2vw15qm9f49ara4i(49nyhoepyg9442t9cbnq6so0fpyzaoroz8aoqarrx80k9\n\n(http://example.com/(test)))))\n\nhttp://example.com/a)b\n\nu4kjpg3e6ilfpqfr");
+add("selser", "Parenthesis in external links, especially URL links (Parsoid)
[2,3,2,0,0,4,3,4,[3,[2]],0,[2,1],0,[4],2,1]",
"k8n60mtqgr4o0f6r\n\nhttp://example.com)gngia9x64hhhncdi\nhttp://example.com/test)\n\nhttp://example.com/(test)jfa1bwkf8yqfrmle0ktqsit2ihpvi\n[http://example.com/(test))
jdw91ewlb5gkfbt9http://example.com/(test))]\n\nc3qqa6ml7jw3tyb9(http://example.com/(test)))))\n\ndqq5g7yp3h1fko6r3fypipqv17xvfgvi\n\n[http://example.com)
foo]");
+add("selser", "Parenthesis in external links, especially URL links (Parsoid)
[[[4],0],0,[2,2],3,1,0,3,0,0,4,3,3,4,4,[2]]", "[http://example.com
fl1a7jhmcdmzehfr])\n\njkk4bcx615cm1jorhttp://example.com/test1hxor6kgsulq5mi)\n\nhttp://example.com/(test)\n\n(http://example.com/(test))yiujz8ii4fagu8fryjrmzmmo20uow291e4tmjal3anhfr\n6qpkqpm9iwetrzfr[http://example.com)
foo]");
+add("selser", "Parenthesis in external links, especially URL links (Parsoid)
[3,0,[3,0],4,3,0,1,0,0,4,[4,2],0,0,0,[1]]",
"\n)l3it50625nopqfr\n\nhttp://example.com/((test)\n\n(http://example.com/(test))3bt75bv0qzl1sjor\nr4upkqvctm15g66rb96h50t7wb6s9k9http://example.com/(test)))))\n\nhttp://example.com/a)b\n\n[http://example.com)
foo]");
add("selser", "Unclosed and unmatched quotes (parsoid)
[[2],0,1,0,3,4,4,4,1,3,2,3,2,0,4,3,4,0,3,0,3]", "gkgdv1qbmarftj4i'''''Bold
italic text '''with bold deactivated''' in between.'''''\n\n'''''Bold italic
text ''with italic deactivated'' in
between.'''''\n\nojtbfs4sctjd1jor9ue40eyn9r6647viakjttdrva0x561or\n\n'''Bold
tag left open'''y7wlx4oue05jc3di\n\n''Italic tag left
open4tnsfee160tfbt9\nNormal text.\n\n9rwpazda7ztwqaor5pqntc8lj8gds4i\n");
add("selser", "Unclosed and unmatched quotes (parsoid)
[4,0,1,0,3,0,3,0,1,3,2,0,0,3,2,0,[[3],3,0,0,0,0],2,[[3,4],2,0],0,[2,[2],3]]",
"x37lpmqyiamaq0k9\n\n'''''Bold italic text ''with italic deactivated'' in
between.'''''\n\n'''Bold tag left open'''d2c05ss7a8vbzkt9\n\n''Italic tag left
open\n\nNormal text.pibmmyeyw8iod2t9<!-- Unmatching number of opening, closing
tags: -->\n''''''''should'' beat '''last
year''''s.6s11f4re3bsrwwmi\n\n''3f0kmvh4p4n7y14i''yhi70ps2s739dx6r'''Susan'''s.\n\ntxueigmp3xlayviPlain
''qcz9bhas4qjjor<nowiki>italic'</nowiki>''\n");
add("selser", "Unclosed and unmatched quotes (parsoid)
[4,0,2,4,3,3,1,3,[[3]],0,2,0,0,4,0,0,1,4,[2,1,0],0,2]",
"za7n0q1inzwoecdi\n\nv66btz3b50jrwwmi\n\n'''''Bold italic text ''with italic
deactivated'' in between.'''''eill0hxdaydp9zfr\n..spanning two paragraphs
(should not work).''''''\n\n''''''\n\nti11n069v65ka9k9\n\n''Italic tag left
open\n\nNormal text.bvx3vjhanwkd42t9<!-- Unmatching number of opening, closing
tags: -->\n'''This year''''s election ''should'' beat '''last
year''''s.twpgscfje6hcl3di\n\nnp1or0qszky8ehfr''Tom'''s car is bigger than
''<nowiki/>'''Susan'''s.\n\ni90pw2quboi529\n\nPlain ''italic'''s plain");
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index 6a96970..48ecf20 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -4032,6 +4032,70 @@
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a></p>
!! end
+!! test
+Parenthesis in external links, especially URL links
+!! options
+php
+!! input
+http://example.com)
+
+http://example.com/test)
+
+http://example.com/(test)
+
+http://example.com/((test)
+
+(http://example.com/(test))
+
+(http://example.com/(test)))))
+
+http://example.com/a)b
+
+[http://example.com) foo]
+!! result
+<p><a rel="nofollow" class="external free"
href="http://example.com">http://example.com</a>)
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/test">http://example.com/test</a>)
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/(test)">http://example.com/(test)</a>
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/((test)">http://example.com/((test)</a>
+</p><p>(<a rel="nofollow" class="external free"
href="http://example.com/(test))">http://example.com/(test))</a>
+</p><p>(<a rel="nofollow" class="external free"
href="http://example.com/(test)))))">http://example.com/(test)))))</a>
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/a)b">http://example.com/a)b</a>
+</p><p><a rel="nofollow" class="external text"
href="http://example.com)">foo</a>
+</p>
+!! end
+
+!! test
+Parenthesis in external links, especially URL links (Parsoid)
+!! options
+parsoid
+!! input
+http://example.com)
+
+http://example.com/test)
+
+http://example.com/(test)
+
+http://example.com/((test)
+
+(http://example.com/(test))
+
+(http://example.com/(test)))))
+
+http://example.com/a)b
+
+[http://example.com) foo]
+!! result
+<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a>)</p>
+<p><a rel="mw:ExtLink"
href="http://example.com/test">http://example.com/test</a>)</p>
+<p><a rel="mw:ExtLink"
href="http://example.com/(test)">http://example.com/(test)</a></p>
+<p><a rel="mw:ExtLink"
href="http://example.com/((test)">http://example.com/((test)</a></p>
+<p>(<a rel="mw:ExtLink"
href="http://example.com/(test))">http://example.com/(test))</a></p>
+<p>(<a rel="mw:ExtLink"
href="http://example.com/(test)))))">http://example.com/(test)))))</a></p>
+<p><a rel="mw:ExtLink"
href="http://example.com/a)b">http://example.com/a)b</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com)">foo</a></p>
+!! end
+
+
###
### Quotes
###
--
To view, visit https://gerrit.wikimedia.org/r/101341
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib09009dd5be74f78bdfcf784f734c9e1067667ea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits