Skip to content

Commit 24835ed

Browse files
author
Simeon Cheeseman
committed
Merge pull request textAngular#363 from lukaszfiszer/unsafe-sanitizer-paste
fix(taBind): Respect ta-unsafe-sanitizer attribute on copy-paste
2 parents f42ec7c + a052008 commit 24835ed

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/textAngular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
12311231
text = dom.html();
12321232
}
12331233

1234-
text = taSanitize(text);
1234+
text = taSanitize(text, '', _disableSanitizer);
12351235
taSelection.insertHtml(text);
12361236
$timeout(function(){
12371237
ngModel.$setViewValue(_compileHtml());

test/taBind/taBind.events.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,45 @@ describe('taBind.events', function () {
122122
}));
123123
});
124124
});
125+
126+
describe('on content-editable with ta-unsafe-sanitizer=true attribute', function () {
127+
var $rootScope, element, $timeout;
128+
beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_, $document, $window) {
129+
$rootScope = _$rootScope_;
130+
$timeout = _$timeout_;
131+
$rootScope.html = '<p>Test Contents</p>';
132+
element = _$compile_('<div contenteditable="true" ta-unsafe-sanitizer="true" ta-bind ng-model="html"></div>')($rootScope);
133+
$document.find('body').append(element);
134+
$rootScope.$digest();
135+
var sel = $window.rangy.getSelection();
136+
var range = $window.rangy.createRangyRange();
137+
range.selectNodeContents(element.find('p')[0]);
138+
sel.setSingleRange(range);
139+
}));
140+
afterEach(function(){
141+
element.remove();
142+
});
143+
144+
// var text = (e.originalEvent || e).clipboardData.getData('text/plain') || $window.clipboardData.getData('Text');
145+
describe('should update model from paste keeping all styles', function () {
146+
it('non-ie based w/o jquery', inject(function($window){
147+
element.triggerHandler('paste', {clipboardData: {types: ['text/html'], getData: function(){ return '<span style="font-size:10px">Test 4 Content</span>'; }}});
148+
$timeout.flush();
149+
$rootScope.$digest();
150+
expect($rootScope.html).toBe('<p><span style="font-size:10px">Test 4 Content</span></p>');
151+
}));
152+
153+
it('non-ie based w/ jquery', inject(function($window){
154+
element.triggerHandler('paste', {originalEvent: {clipboardData: {types: ['text/html'], getData: function(){ return '<span style="font-size:10px">Test 4 Content</span>';} }}});
155+
$timeout.flush();
156+
$rootScope.$digest();
157+
expect($rootScope.html).toBe('<p><span style="font-size:10px">Test 4 Content</span></p>');
158+
}));
159+
160+
});
161+
162+
});
163+
125164
});
126165

127166
describe('emits the ta-drop-event event correctly', function(){

0 commit comments

Comments
 (0)