-
Notifications
You must be signed in to change notification settings - Fork 2
Sp trusted #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdasberg
wants to merge
6
commits into
master
Choose a base branch
from
spTrusted
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sp trusted #5
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d9f417
Added ng-sanitize as it is a requirement
mdasberg 94c8fbc
Adde ngSanitze to ngdocs task as it is a requirement
mdasberg 63b499a
Added spTrusted filter
mdasberg 4f73dc0
Merge remote-tracking branch 'origin/master' into spTrusted
mdasberg 65340f0
Renamed mock so we can have multiple next to each other
mdasberg 10abbaf
Renamed mock so we can have multiple next to each other
mdasberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 +1,11 @@ | ||
| { | ||
| "name": "SpectingularJS", | ||
| "version": "0.0.0", | ||
| "devDependencies": { | ||
| "angular": "~1.2.16", | ||
| "angular-mocks": "~1.2.16", | ||
| "bootstrap": "~3.1.1", | ||
| "jasmine-jquery": "~2.0.3" | ||
| "name": "SpectingularJS", | ||
| "version": "0.0.0", | ||
| "devDependencies": { | ||
| "angular": "~1.2.16", | ||
| "angular-sanitize": "~1.2.16", | ||
| "angular-mocks": "~1.2.16", | ||
| "bootstrap": "~3.1.1", | ||
| "jasmine-jquery": "~2.0.3" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,35 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * @ngdoc filter | ||
| * @name sp.utility.filter:spTrusted | ||
| * | ||
| * @description | ||
| * Filter for trusting html. | ||
| * | ||
| * @example | ||
| <example module="spTrustedExample"> | ||
| <file name="index.html"> | ||
| <div ng-controller="ctrl"> | ||
| <h3>trusted</h3> | ||
| <div ng-bind-html="snippet | spTrusted"></div> | ||
| <h3>untrusted</h3> | ||
| <div ng-bind-html="snippet"></div> | ||
| </div> | ||
| </file> | ||
|
|
||
| <file name="scripts.js"> | ||
| angular.module('spTrustedExample', ['sp.utility']). | ||
| controller('ctrl', function($scope) { | ||
| $scope.snippet = '<p style="color:blue">an html\n<em onmouseover="this.textContent=\'PWN3D!\'">hover</em>\nsnippet</p>'; | ||
| }); | ||
| </file> | ||
| </example> | ||
| **/ | ||
|
|
||
| angular.module('sp.utility') | ||
| .filter('spTrusted', ['$sce', function ($sce) { | ||
| return function (text) { | ||
| return $sce.trustAsHtml(text); | ||
| }; | ||
| }]); | ||
This file contains hidden or 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 hidden or 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,9 @@ | ||
| var spTrustedMocks = { | ||
| snippet: '<p style="color:blue">an html\n<em onmouseover="this.textContent=\'PWN3D!\'">hover</em>\nsnippet</p>', | ||
| unsafe: 'this.textContent=\'PWN3D!\'', | ||
| safe: '' | ||
| }; | ||
|
|
||
| module.exports = { | ||
| spTrustedMocks: spTrustedMocks | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>spTrusted Spec</title> | ||
| <script src="/bower_components/jquery/dist/jquery.min.js"></script> | ||
| <script src="/bower_components/angular/angular.js"></script> | ||
| <script src="/bower_components/angular-sanitize/angular-sanitize.js"></script> | ||
| <script src="/src/sp/sp.js"></script> | ||
| <script src="/src/sp/utility/spTrusted.js"></script> | ||
|
|
||
| <script type="text/javascript"> | ||
| angular.module("spTrusted", ['sp.utility']). | ||
| controller('ctrl', ['$scope', function ($scope) { | ||
| $scope.snippet = '<p style="color:blue">an html\n<em onmouseover="this.textContent=\'PWN3D!\'">hover</em>\nsnippet</p>'; | ||
| }]); | ||
| </script> | ||
| </head> | ||
| <body ng-app="spTrusted"> | ||
| <div ng-controller="ctrl"> | ||
| trusted:<br/> | ||
| <div id="trusted" ng-bind-html="snippet | spTrusted"></div><br/> | ||
|
|
||
| untrusted:<br/> | ||
| <div id="untrusted" ng-bind-html="snippet"></div><br/> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or 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,17 @@ | ||
| 'use strict'; | ||
|
|
||
| var mocks = require('../../../mocks/sp/utility/spTrustedMock').spTrustedMocks; | ||
|
|
||
| describe('spTrusted filter', function () { | ||
| beforeEach(function () { | ||
| browser.get('/test/protractor/sp/utility/spTrusted.html'); | ||
| }); | ||
|
|
||
| it('should trust unsafe html', function () { | ||
| expect(element(by.id('trusted')).element(by.tagName('em')).getAttribute('onmouseover')).toEqual(mocks.unsafe); | ||
| }); | ||
|
|
||
| it('should not trust unsafe html', function () { | ||
| expect(element(by.id('untrusted')).getInnerHtml()).toEqual(mocks.safe); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,23 @@ | ||
| 'use strict'; | ||
|
|
||
| describe('spTrusted filter', function () { | ||
| var snippet = '<p style="color:blue">an html\n<em onmouseover="this.textContent=\'PWN3D!\'">hover</em>\nsnippet</p>'; | ||
| var element, scope; | ||
|
|
||
| beforeEach(function() { | ||
| module('sp.utility'); | ||
| inject(function($rootScope, $compile) { | ||
| scope = $rootScope; | ||
| element = angular.element( | ||
| '<div ng-bind-html="snippet | spTrusted"></div>' | ||
| ); | ||
| scope.snippet = snippet; | ||
| $compile(element)(scope); | ||
| scope.$digest(); | ||
| }) | ||
| }); | ||
|
|
||
| it('should trust html', function () { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could use a baseline check: what happens when you don't use the filter with the same input? |
||
| expect(element.html()).toEqual(snippet); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the other trustAsX methods? Shouldn't this at least have "html" in the name somewhere?