Avoid breaking full phabricator URLs

Unpublished Commit · Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit no longer exists in the repository. It may have been part of a branch which was deleted.This commit has been deleted in the repository: it is no longer reachable from any branch, tag, or ref.


Avoid breaking full phabricator URLs

This is an alternative to I20edf8e.

This patch does two things. If you think I should split this into two
patches, please tell me which one will be merged first.

  1. The negative lookahead (?!["<]) avoids the detection of ticket ids

in links. For example, the two ticket numbers in
<a href="https://phabricator.wikimedia.org/T1">T1</a> will not be
detected any more. Note that ECMAScript does support lookaheads, but
does not support lookbehinds.

  1. The additional (#\d+)? allows to link comments in tickets.

Note that I did not actually test this in Gerrit. Instead I wrote
this for testing:

var match = "\\bT(\\d+)(#\\d+)?\\b(?![#\"<])",
link = "https://phabricator.wikimedia.org/T$1$2",
regex = new RegExp( match, 'g' ),
text = 'T1\n'

		+ 'T2#2\n'
		+ '<a href="http://T3">T3</a>\n'
		+ '<a href="http://T4#4">T4</a>';

document.write( text
.replace( regex, '<a href="' + link + '">T$1</a>' )
.replace( /</g, '&lt;' ) );

Bug: T75997
Bug: T76459
Change-Id: I2f06f93b6f7b42815c3594fd6902b078ea5a020e


thiemowmdeAuthored on Dec 3 2015, 11:56 AM
mmodellCommitted on Jun 10 2016, 6:37 PM

Commit No Longer Exists

This commit no longer exists in the repository.