Skip to content

Commit 65fa01f

Browse files
committed
Take local URLs into account
1 parent 7f8e87d commit 65fa01f

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

dist/Autolinker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3712,14 +3712,15 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
37123712

37133713
offset += res[1].length;
37143714
urlMatch = urlMatch.slice(res[1].length);
3715-
if (/^[^.A-Za-z:\/?#]/.test(urlMatch)) {
3715+
if (/^[^.A-Za-z0-9:\/?#]/.test(urlMatch)) {
37163716
return offset;
37173717
}
37183718

37193719
return -1;
37203720
}
37213721

37223722
} );
3723+
37233724
/*global Autolinker */
37243725
/*jshint scripturl:true */
37253726
/**

dist/Autolinker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/matcher/Url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
299299

300300
offset += res[1].length;
301301
urlMatch = urlMatch.slice(res[1].length);
302-
if (/^[^.A-Za-z:\/?#]/.test(urlMatch)) {
302+
if (/^[^.A-Za-z0-9:\/?#]/.test(urlMatch)) {
303303
return offset;
304304
}
305305

306306
return -1;
307307
}
308308

309-
} );
309+
} );

tests/matcher/UrlSpec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ describe( "Autolinker.matcher.Url", function() {
9393
MatchChecker.expectUrlMatch( matches[ 0 ], 'https://gitlab.example.com/search?utf8=✓&search=mysearch&group_id=&project_id=42&search_code=true&repository_ref=master', 0 );
9494
});
9595

96+
it( 'should match any local URL with http before', function() {
97+
var matches = matcher.parseMatches( 'http://localhost.local001/test' );
98+
var othermatches = matcher.parseMatches( 'http://suus111.w10:8090/display/test/AI' );
99+
100+
expect( matches.length ).toBe( 1 );
101+
expect( othermatches.length ).toBe( 1 );
102+
MatchChecker.expectUrlMatch( matches[ 0 ], 'http://localhost.local001/test', 0 );
103+
MatchChecker.expectUrlMatch( othermatches[ 0 ], 'http://suus111.w10:8090/display/test/AI', 0 );
104+
});
105+
106+
it( 'should not match a local URL that does not have the http before', function() {
107+
var matches = matcher.parseMatches( 'localhost.local001/test' );
108+
109+
expect( matches.length ).toBe( 0 );
110+
});
96111

97112
describe( 'protocol-relative URLs', function() {
98113

@@ -130,4 +145,4 @@ describe( "Autolinker.matcher.Url", function() {
130145

131146
} );
132147

133-
} );
148+
} );

0 commit comments

Comments
 (0)