Skip to content

Commit

Permalink
fix(withinString): properly handle contained balanced parens - closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jan 29, 2017
1 parent bff8674 commit c72ffca
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The release notes tracked in this document are also made available on the [relea
### master

* prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321)
* fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to properly handle fully contained parentheses - [Issue #325](https://github.com/medialize/URI.js/issues/325)

### 1.18.4 (December 4th 2016) ###

Expand Down
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@
}

if (parensEnd > -1) {
slice = slice.slice(0, parensEnd) + slice.slice(parensEnd + 1).replace(_trim, '');
slice = slice.slice(0, parensEnd) + slice.slice(parensEnd).replace(_trim, '');
} else {
slice = slice.replace(_trim, '');
}
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1585,14 +1585,14 @@
+ 'http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n'
+ 'http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n'
+ 'links can also be in parens (http://example.org) or quotes »http://example.org«, '
+ 'yet https://example.com/with_(balanced_parentheses) contains the closing parens, but '
+ 'yet https://example.com/with_(balanced_parentheses) and https://example.com/with_(balanced_parentheses).txt contain the closing parens, but '
+ 'https://example.com/with_unbalanced_parentheses) does not.';
var expected = 'Hello <a>www.example.com</a>,\n'
+ '<a>http://google.com</a> is a search engine, like <a>http://www.bing.com</a>\n'
+ '<a>http://exämple.org/foo.html?baz=la#bumm</a> is an IDN URL,\n'
+ '<a>http://123.123.123.123/foo.html</a> is IPv4 and <a>http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html</a> is IPv6.\n'
+ 'links can also be in parens (<a>http://example.org</a>) or quotes »<a>http://example.org</a>«, '
+ 'yet <a>https://example.com/with_(balanced_parentheses)</a> contains the closing parens, but '
+ 'yet <a>https://example.com/with_(balanced_parentheses)</a> and <a>https://example.com/with_(balanced_parentheses).txt</a> contain the closing parens, but '
+ '<a>https://example.com/with_unbalanced_parentheses</a>) does not.';
/*jshint laxbreak: false */
var result = URI.withinString(source, function(url) {
Expand Down

0 comments on commit c72ffca

Please sign in to comment.