This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Switches to use `ng-bind-html` from `bind-html-unsafe` BREAKING CHANGE: This modifies the typeahead to use the the `$sce` service instead when `ngSanitize` is present Closes #3463 Resolves #4073
- Loading branch information
1 parent
aaec2f4
commit bb9fa1a
Showing
9 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe('Security concerns', function() { | ||
var highlightFilter, $sanitize, logSpy; | ||
|
||
beforeEach(module('ui.bootstrap.typeahead', 'ngSanitize')); | ||
|
||
beforeEach(inject(function (typeaheadHighlightFilter, _$sanitize_, $log) { | ||
highlightFilter = typeaheadHighlightFilter; | ||
$sanitize = _$sanitize_; | ||
logSpy = spyOn($log, 'warn'); | ||
})); | ||
|
||
it('should not call the $log service when ngSanitize is present', function() { | ||
highlightFilter('before <script src="">match</script> after', 'match'); | ||
expect(logSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,51 @@ | ||
describe('typeaheadHighlight', function() { | ||
var highlightFilter; | ||
describe('typeaheadHighlight', function () { | ||
|
||
var highlightFilter, $log, $sce, logSpy; | ||
|
||
beforeEach(module('ui.bootstrap.typeahead')); | ||
|
||
beforeEach(inject(function(_$log_, _$sce_) { | ||
$log = _$log_; | ||
$sce = _$sce_; | ||
logSpy = spyOn($log, 'warn'); | ||
})); | ||
|
||
beforeEach(inject(function(typeaheadHighlightFilter) { | ||
highlightFilter = typeaheadHighlightFilter; | ||
})); | ||
|
||
it('should higlight a match', function() { | ||
expect(highlightFilter('before match after', 'match')).toEqual('before <strong>match</strong> after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before match after', 'match'))).toEqual('before <strong>match</strong> after'); | ||
}); | ||
|
||
it('should higlight a match with mixed case', function() { | ||
expect(highlightFilter('before MaTch after', 'match')).toEqual('before <strong>MaTch</strong> after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before MaTch after', 'match'))).toEqual('before <strong>MaTch</strong> after'); | ||
}); | ||
|
||
it('should higlight all matches', function() { | ||
expect(highlightFilter('before MaTch after match', 'match')).toEqual('before <strong>MaTch</strong> after <strong>match</strong>'); | ||
expect($sce.getTrustedHtml(highlightFilter('before MaTch after match', 'match'))).toEqual('before <strong>MaTch</strong> after <strong>match</strong>'); | ||
}); | ||
|
||
it('should do nothing if no match', function() { | ||
expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before match after', 'nomatch'))).toEqual('before match after'); | ||
}); | ||
|
||
it('should do nothing if no or empty query', function() { | ||
expect(highlightFilter('before match after', '')).toEqual('before match after'); | ||
expect(highlightFilter('before match after', null)).toEqual('before match after'); | ||
expect(highlightFilter('before match after', undefined)).toEqual('before match after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before match after', ''))).toEqual('before match after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before match after', null))).toEqual('before match after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before match after', undefined))).toEqual('before match after'); | ||
}); | ||
|
||
it('issue 316 - should work correctly for regexp reserved words', function() { | ||
expect(highlightFilter('before (match after', '(match')).toEqual('before <strong>(match</strong> after'); | ||
expect($sce.getTrustedHtml(highlightFilter('before (match after', '(match'))).toEqual('before <strong>(match</strong> after'); | ||
}); | ||
|
||
it('issue 1777 - should work correctly with numeric values', function() { | ||
expect(highlightFilter(123, '2')).toEqual('1<strong>2</strong>3'); | ||
expect($sce.getTrustedHtml(highlightFilter(123, '2'))).toEqual('1<strong>2</strong>3'); | ||
}); | ||
|
||
it('should show a warning when this component is being used unsafely', function() { | ||
highlightFilter('<i>before</i> match after', 'match'); | ||
expect(logSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<a href tabindex="-1" bind-html-unsafe="match.label | typeaheadHighlight:query"></a> | ||
<a href tabindex="-1" ng-bind-html="match.label | typeaheadHighlight:query"></a> |