Merge "Allow commitLink replacements overlap"
This commit is contained in:
@@ -175,5 +175,28 @@ limitations under the License.
|
||||
assert.equal(element.$.output.innerHTML, 'foo:baz');
|
||||
});
|
||||
|
||||
test('overlapping links', function() {
|
||||
element.config = {
|
||||
b1: {
|
||||
match: '(B:\\s*)(\\d+)',
|
||||
html: '$1<a href="ftp://foo/$2">$2</a>',
|
||||
},
|
||||
b2: {
|
||||
match: '(B:\\s*\\d+\\s*,\\s*)(\\d+)',
|
||||
html: '$1<a href="ftp://foo/$2">$2</a>',
|
||||
},
|
||||
};
|
||||
element.content = '- B: 123, 45';
|
||||
var links = Polymer.dom(element.root).querySelectorAll('a');
|
||||
|
||||
assert.equal(links.length, 2);
|
||||
assert.equal(element.$$('span').textContent, '- B: 123, 45');
|
||||
|
||||
assert.equal(links[0].href, 'ftp://foo/123');
|
||||
assert.equal(links[0].textContent, '123');
|
||||
|
||||
assert.equal(links[1].href, 'ftp://foo/45');
|
||||
assert.equal(links[1].textContent, '45');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -165,12 +165,27 @@ GrLinkTextParser.prototype.parseLinks = function(text, patterns) {
|
||||
var result = match[0].replace(pattern,
|
||||
patterns[p].html || patterns[p].link);
|
||||
|
||||
// Skip portion of replacement string that is equal to original.
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i] !== match[0][i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = result.slice(i);
|
||||
|
||||
if (patterns[p].html) {
|
||||
this.addHTML(
|
||||
result, susbtrIndex + match.index, match[0].length, outputArray);
|
||||
result,
|
||||
susbtrIndex + match.index + i,
|
||||
match[0].length - i,
|
||||
outputArray);
|
||||
} else if (patterns[p].link) {
|
||||
this.addLink(match[0], result,
|
||||
susbtrIndex + match.index, match[0].length, outputArray);
|
||||
this.addLink(
|
||||
match[0],
|
||||
result,
|
||||
susbtrIndex + match.index + i,
|
||||
match[0].length - i,
|
||||
outputArray);
|
||||
} else {
|
||||
throw Error('linkconfig entry ' + p +
|
||||
' doesn’t contain a link or html attribute.');
|
||||
|
||||
Reference in New Issue
Block a user