[mb-commits] branch, beta, updated. MBS-5838: Fix format_edit_note to preserve whitespace around links
MusicBrainz Git Server <[email protected]> Thu, 07 Feb 2013 06:51:58 +0000
| Newsgroups | gmane.comp.audio.musicbrainz.cvs |
|---|---|
| Message-ID | <E1U3LKw-0006OZ-Me@wiley> |
The branch, beta has been updated
via http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=b7a19b2d7b33c3f0f8fb18525e5b7118ff9d704b (commit)
from http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=5d3c75e38cc9959fb7cade531951d4ea0cae7895 (commit)
Summary of changes:
lib/MusicBrainz/Server/Filters.pm | 5 ++++-
t/lib/t/MusicBrainz/Server/Filters.pm | 8 ++++++++
2 files changed, 12 insertions(+), 1 deletions(-)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b7a19b2d7b33c3f0f8fb18525e5b7118ff9d704b
Author: Oliver Charles <[email protected]>
Date: Thu Feb 7 11:12:06 2013 +0000
MBS-5838: Fix format_edit_note to preserve whitespace around links
Add more tests to MusicBrainz::Server::Filters::format_edit_note to make sure
that if a link follows some plain text and whitespace, the text and whitespace
is preserved. 95c57dbcf added a schema-independent URLs, but in doing so would
strip any leading whitespace before the URL. I've now changed the starting URL
boundary to be either the start of the edit note, or a negative look behind for
':'.
diff --git a/lib/MusicBrainz/Server/Filters.pm b/lib/MusicBrainz/Server/Filters.pm
index e514b15..66f5860 100644
--- a/lib/MusicBrainz/Server/Filters.pm
+++ b/lib/MusicBrainz/Server/Filters.pm
@@ -150,7 +150,10 @@ sub format_editnote
# The following taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
$html =~ s{
- (?:^|[^\w:]) # Start with a non-word character (that is not :), or the beginning of the edit note.
+ # Match the start of the edit note entirely, or ensure that the proceeding
+ # character is not a : (as we don't want to match foo://bar.com as
+ # foo:<a..>).
+ (?:^|(?<!:))
( # Capture 1: entire matched URL
(?:
(?:https?:)?// # http or https protocol
diff --git a/t/lib/t/MusicBrainz/Server/Filters.pm b/t/lib/t/MusicBrainz/Server/Filters.pm
index 3e815c3..fd9424f 100644
--- a/t/lib/t/MusicBrainz/Server/Filters.pm
+++ b/t/lib/t/MusicBrainz/Server/Filters.pm
@@ -19,6 +19,14 @@ test 'Edit note syntax' => sub {
is(format_editnote("https://musicbrainz.org"),
'<a href="https://musicbrainz.org">https://musicbrainz.org</a>', 'https links are created');
+ is(format_editnote("I <3 https://musicbrainz.org"),
+ 'I <3 <a href="https://musicbrainz.org">https://musicbrainz.org</a>',
+ 'Links are created, whitespace is preserved, angular brackets are escaped');
+
+ is(format_editnote("I <3 //musicbrainz.org"),
+ 'I <3 <a href="//musicbrainz.org">//musicbrainz.org</a>',
+ 'Schema independent links are created, whitespace is preserved, angular brackets are escaped');
+
is(format_editnote("//musicbrainz.org"),
'<a href="//musicbrainz.org">//musicbrainz.org</a>');
-----------------------------------------------------------------------
hooks/post-receive
--
mb_server