Skip to content

Commit

Permalink
Fix WTS regression in iswiki when link prefix and link trail overlap.
Browse files Browse the repository at this point in the history
See example regression in the comments of
I5ae8435322c78dd1df170d7a3543fff3642759b1.

Change-Id: I30d98cd35a8260c0b2b8d18beb10d7a286c624a5
  • Loading branch information
cscott committed Jan 23, 2015
1 parent de5569a commit 88605a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/wts.ConstrainedText.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var escapeLine = function(line, cb) {
line: line,
pos: 0,
};
var safeLeft = '';
for (state.pos = 0; state.pos < line.length; state.pos++) {
var chunk = line[state.pos];
// Process the escapes for this chunk, given escaped previous chunk
Expand All @@ -54,9 +55,16 @@ var escapeLine = function(line, cb) {
if (cb) {
cb(state.leftContext.slice(origPos), chunk.node);
}
if (thisEscape.greedy) {
// protect the left context: this will be matched greedily
// by this chunk, so there's no chance that a subsequent
// token will include this in its prefix.
safeLeft += state.leftContext;
state.leftContext = '';
}
}
// right context should be empty here.
return state.leftContext;
return safeLeft + state.leftContext;
};

/**
Expand Down Expand Up @@ -255,8 +263,22 @@ var WikiLinkText = function WikiLinkText(text, node, wikiConfig, type) {
badPrefix: noTrails ? undefined : wikiConfig.linkPrefixRegex,
badSuffix: noTrails ? undefined : wikiConfig.linkTrailRegex,
});
// We match link trails greedily when they exist.
if (!(noTrails || /\]$/.test(text))) {
this.greedy = true;
}
};
inherits(WikiLinkText, RegExpConstrainedText);
WikiLinkText.prototype.escape = function(state) {
var r = WikiLinkText.super_.prototype.escape.call(this, state);
// If previous token was also a WikiLink, its linktrail will
// eat up any possible linkprefix characters, so we don't need
// a <nowiki> in this case. (Eg: [[a]]-[[b]] in iswiki; the -
// character is both a link prefix and a link trail, but it gets
// preferentially associated with the [[a]] as a link trail.)
r.greedy = this.greedy;
return r;
};
WikiLinkText._fromSelSer = function(text, node, dataParsoid, env) {
// interwiki links have type == 'mw:ExtLink', but they are written
// with [[ ]] and get link trails -- so as far as we're concerned
Expand Down
12 changes: 12 additions & 0 deletions tests/parserTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21173,6 +21173,18 @@ parsoid=html2wt
this is not a link: <nowiki>http://example.com</nowiki>
!! end

!! test
Links 15. Link trails can't become link prefixes.
!! options
language=is
!! wikitext
[[Söfnuður]]-[[00]]
!! html/php
<p><a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">Söfnuður-</a><a href="/wiki/00" title="00">00</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður" data-parsoid='{"stx":"simple","tail":"-"}'>Söfnuður-</a><a rel="mw:WikiLink" href="00" title="00">00</a></p>
!! end

#### --------------- Quotes ---------------
#### 1. Quotes inside <b> and <i>
Expand Down

0 comments on commit 88605a4

Please sign in to comment.