Permalink
Comparing changes
Open a pull request
- 2 commits
- 4 files changed
- 0 commit comments
- 2 contributors
Commits on Dec 02, 2014
The url is the same whether or not there is an empty `#` marker at the end. This prevents unwanted calls to update the browser, since the browser is automatically applying an empty hash if necessary to prevent page reloads. Closes #9635
When smart quotes are included in content filtered through linky, any smart quote at the end of a URL string was being included in the link text and the href. Closes #7307
Unified
Split
Showing
with
24 additions
and 5 deletions.
- +7 −2 src/ng/location.js
- +1 −1 src/ngSanitize/filter/linky.js
- +12 −0 test/ng/locationSpec.js
- +4 −2 test/ngSanitize/filter/linkySpec.js
| @@ -68,6 +68,10 @@ function stripHash(url) { | ||
| return index == -1 ? url : url.substr(0, index); | ||
| } | ||
|
|
||
| function trimEmptyHash(url) { | ||
| return url.replace(/(#.+)|#$/, '$1'); | ||
| } | ||
|
|
||
|
|
||
| function stripFile(url) { | ||
| return url.substr(0, stripHash(url).lastIndexOf('/') + 1); | ||
| @@ -903,10 +907,11 @@ function $LocationProvider() { | ||
|
|
||
| // update browser | ||
| $rootScope.$watch(function $locationWatch() { | ||
| var oldUrl = $browser.url(); | ||
| var oldUrl = trimEmptyHash($browser.url()); | ||
| var newUrl = trimEmptyHash($location.absUrl()); | ||
| var oldState = $browser.state(); | ||
| var currentReplace = $location.$$replace; | ||
| var urlOrStateChanged = oldUrl !== $location.absUrl() || | ||
| var urlOrStateChanged = oldUrl !== newUrl || | ||
| ($location.$$html5 && $sniffer.history && oldState !== $location.$$state); | ||
|
|
||
| if (initializing || urlOrStateChanged) { | ||
| @@ -104,7 +104,7 @@ | ||
| */ | ||
| angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) { | ||
| var LINKY_URL_REGEXP = | ||
| /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/, | ||
| /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"”’]/, | ||
| MAILTO_REGEXP = /^mailto:/; | ||
|
|
||
| return function(text, target) { | ||
| @@ -647,6 +647,18 @@ describe('$location', function() { | ||
| }; | ||
| } | ||
|
|
||
| describe('location watch', function() { | ||
| beforeEach(initService({supportHistory: true})); | ||
| beforeEach(inject(initBrowser({url:'http://new.com/a/b#'}))); | ||
|
|
||
| it('should not update browser if only the empty hash fragment is cleared by updating the search', inject(function($rootScope, $browser, $location) { | ||
| $browser.url('http://new.com/a/b#'); | ||
| var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough(); | ||
| $rootScope.$digest(); | ||
| expect($browserUrl).not.toHaveBeenCalled(); | ||
| })); | ||
| }); | ||
|
|
||
| describe('wiring', function() { | ||
|
|
||
| beforeEach(initService({html5Mode:false,hashPrefix: '!',supportHistory: true})); | ||
| @@ -10,11 +10,13 @@ describe('linky', function() { | ||
| })); | ||
|
|
||
| it('should do basic filter', function() { | ||
| expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")). | ||
| expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c “http://example.com” ‘http://me.com’")). | ||
| toEqual('<a href="http://ab/">http://ab/</a> ' + | ||
| '(<a href="http://a/">http://a/</a>) ' + | ||
| '<<a href="http://a/">http://a/</a>> ' + | ||
| '<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c'); | ||
| '<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c ' + | ||
| '“<a href="http://example.com">http://example.com</a>” ' + | ||
| '‘<a href="http://me.com">http://me.com</a>’'); | ||
| expect(linky(undefined)).not.toBeDefined(); | ||
| }); | ||
|
|
||