Remove zero space char from linkify
In a previous change, a zero space char was added in order for linkify to not link R= as part of am email address. At the time, we concluded that a zero width space would not be an issue for users. After receiving a complaint, this change removes the added zero width space after linkificataion. Because the space has to get removed in the linked text parser, an optional parameter is added to gr-linked-text indicating that this removal will need to take place. Because it is only needed in the commit message, this avoids doing the replacement search for all other linked text areas. Bug: Issue 5339 Change-Id: I3d7b29106cafab61193e6fb65225fc3325104756
This commit is contained in:
@@ -316,7 +316,8 @@ limitations under the License.
|
||||
content="{{_latestCommitMessage}}">
|
||||
<gr-linked-text pre
|
||||
content="[[_latestCommitMessage]]"
|
||||
config="[[_projectConfig.commentlinks]]"></gr-linked-text>
|
||||
config="[[_projectConfig.commentlinks]]"
|
||||
remove-zero-width-space></gr-linked-text>
|
||||
</gr-editable-content>
|
||||
<gr-button link
|
||||
class="editCommitMessage"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
is: 'gr-linked-text',
|
||||
|
||||
properties: {
|
||||
removeZeroWidthSpace: Boolean,
|
||||
content: {
|
||||
type: String,
|
||||
observer: '_contentChanged',
|
||||
@@ -62,7 +63,7 @@
|
||||
} else if (fragment) {
|
||||
output.appendChild(fragment);
|
||||
}
|
||||
});
|
||||
}, this.removeZeroWidthSpace);
|
||||
parser.parse(content);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -178,9 +178,10 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('R=email labels link correctly', function() {
|
||||
element.removeZeroWidthSpace = true;
|
||||
element.content = 'R=\u200Btest@google.com';
|
||||
assert.equal(element.$.output.textContent, 'R=\u200Btest@google.com');
|
||||
assert.equal(element.$.output.innerHTML.match(/(R=\u200B<a)/g).length, 1);
|
||||
assert.equal(element.$.output.textContent, 'R=test@google.com');
|
||||
assert.equal(element.$.output.innerHTML.match(/(R=<a)/g).length, 1);
|
||||
});
|
||||
|
||||
test('overlapping links', function() {
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
function GrLinkTextParser(linkConfig, callback) {
|
||||
function GrLinkTextParser(linkConfig, callback, opt_removeZeroWidthSpace) {
|
||||
this.linkConfig = linkConfig;
|
||||
this.callback = callback;
|
||||
this.removeZeroWidthSpace = opt_removeZeroWidthSpace;
|
||||
Object.preventExtensions(this);
|
||||
}
|
||||
|
||||
@@ -128,6 +129,11 @@ GrLinkTextParser.prototype.parse = function(text) {
|
||||
};
|
||||
|
||||
GrLinkTextParser.prototype.parseChunk = function(text, href) {
|
||||
if (this.removeZeroWidthSpace) {
|
||||
// Remove the zero-width space added in gr-change-view.
|
||||
text = text.replace(/^R=\u200B/gm, 'R=');
|
||||
}
|
||||
|
||||
if (href) {
|
||||
this.addText(text, href);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user