Fix regex in link-text-parser
Change-Id: Idccdf04073367dd912fec35f902977e2b39f26d8
This commit is contained in:
@@ -69,6 +69,10 @@ limitations under the License.
|
||||
match: 'test (.+)',
|
||||
html: '<a href="/r/awesomesauce">$1</a>',
|
||||
},
|
||||
anotatstartwithbaseurl: {
|
||||
match: 'a test (.+)',
|
||||
html: '[Lookup: <a href="/r/awesomesauce">$1</a>]',
|
||||
},
|
||||
disabledconfig: {
|
||||
match: 'foo:(.+)',
|
||||
link: 'https://google.com/search?q=$1',
|
||||
@@ -212,6 +216,15 @@ limitations under the License.
|
||||
assert.equal(linkEl.textContent, 'foo');
|
||||
});
|
||||
|
||||
test('a is not at start', function() {
|
||||
window.CANONICAL_PATH = '/r';
|
||||
|
||||
element.content = 'a test foo';
|
||||
const linkEl = element.$.output.childNodes[1];
|
||||
assert.isTrue(linkEl.href.endsWith('/r/awesomesauce'));
|
||||
assert.equal(linkEl.textContent, 'foo');
|
||||
});
|
||||
|
||||
test('hash html with base url', function() {
|
||||
window.CANONICAL_PATH = '/r';
|
||||
|
||||
|
@@ -109,7 +109,7 @@ GrLinkTextParser.prototype.addHTML =
|
||||
function(html, position, length, outputArray) {
|
||||
if (!this.hasOverlap(position, length, outputArray)) {
|
||||
if (!!this.baseUrl && html.match(/<a href=\"\//g) &&
|
||||
!new RegExp(`^<a href="${this.baseUrl}`, 'g').test(html)) {
|
||||
!new RegExp(`<a href="${this.baseUrl}`, 'g').test(html)) {
|
||||
html = html.replace(/<a href=\"\//g, `<a href=\"${this.baseUrl}\/`);
|
||||
}
|
||||
this.addItem(null, null, html, position, length, outputArray);
|
||||
|
Reference in New Issue
Block a user