normalizeclipboarddata.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import normalizeClipboardData from '../../src/utils/normalizeclipboarddata';
  6. describe( 'normalizeClipboardData()', () => {
  7. it( 'should strip all span.Apple-converted-space', () => {
  8. expect( normalizeClipboardData(
  9. '<span class="Apple-converted-space"> \t\n</span>x<span class="Apple-converted-space">\u00a0\u00a0</span>'
  10. ) ).to.equal( ' \t\nx\u00a0\u00a0' );
  11. } );
  12. it( 'should replace span.Apple-converted-space of length one with a normal space', () => {
  13. expect(
  14. normalizeClipboardData( '<span class="Apple-converted-space"> </span>x<span class="Apple-converted-space">\u00a0</span>' )
  15. ).to.equal( ' x ' );
  16. } );
  17. it( 'should strip all spans with no attributes', () => {
  18. expect( normalizeClipboardData(
  19. '<span> \t\n</span>x<span>\u00a0\u00a0</span>'
  20. ) ).to.equal( ' \t\nx\u00a0\u00a0' );
  21. } );
  22. it( 'should replace spans with no attributes with a normal space', () => {
  23. expect(
  24. normalizeClipboardData( '<span> </span>x<span>\u00a0</span>' )
  25. ).to.equal( ' x ' );
  26. } );
  27. it( 'should not strip spans with no attributes if they contain anything but spaces', () => {
  28. expect(
  29. normalizeClipboardData( '<span> a</span>x<span>b\u00a0</span>x<span>c</span>' )
  30. ).to.equal( '<span> a</span>x<span>b\u00a0</span>x<span>c</span>' );
  31. } );
  32. it( 'should not replace spans of length 1+ with normal space', () => {
  33. expect(
  34. normalizeClipboardData( '<span> </span>x<span>\u00a0 </span>x<span>\u00a0\u00a0</span>x<span> \u00a0</span>' )
  35. ).to.equal( ' x\u00a0 x\u00a0\u00a0x \u00a0' );
  36. } );
  37. it( 'should not strip spans with any attribute (except span.Apple-converted-space)', () => {
  38. const input =
  39. '<span style="color: red"> </span>x' +
  40. '<span foo="1">\u00a0</span>x' +
  41. '<span foo> </span>x' +
  42. '<span class="bar">\u00a0</span>';
  43. expect( normalizeClipboardData( input ) ).to.equal( input );
  44. } );
  45. it( 'should not be greedy', () => {
  46. expect(
  47. normalizeClipboardData( '<span class="Apple-converted-space"> </span><span foo> </span><span>a</span>' )
  48. ).to.equal( ' <span foo> </span><span>a</span>' );
  49. } );
  50. } );