|
741 | 741 | //
|
742 | 742 |
|
743 | 743 | var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,
|
744 |
| - protectAttributeRegex = /\s(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi; |
| 744 | + // Be greedy while looking for protected attributes. This will let us avoid an unfortunate |
| 745 | + // situation when "nested attributes", which may appear valid, are also protected. |
| 746 | + // I.e. if we consider the following HTML: |
| 747 | + // |
| 748 | + // <img data-x="<a href="X"" /> |
| 749 | + // |
| 750 | + // then the "non-greedy match" returns: |
| 751 | + // |
| 752 | + // 'href' => '"X"' // It's wrong! Href is not an attribute of <img>. |
| 753 | + // |
| 754 | + // while greedy match returns: |
| 755 | + // |
| 756 | + // 'data-x' => '<a href="X"' |
| 757 | + // |
| 758 | + // which, can be easily filtered out (#11508). |
| 759 | + protectAttributeRegex = /((?:\w|-)+)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi, |
| 760 | + protectAttributeNameRegex = /^(href|src|name)$/i; |
745 | 761 |
|
746 | 762 | // Note: we use lazy star '*?' to prevent eating everything up to the last occurrence of </style> or </textarea>.
|
747 | 763 | var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*?<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
|
|
758 | 774 | return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName ) {
|
759 | 775 | // Avoid corrupting the inline event attributes (#7243).
|
760 | 776 | // We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)
|
761 |
| - if ( !( /^on/ ).test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 ) { |
762 |
| - fullAttr = fullAttr.slice( 1 ); // Strip the space. |
| 777 | + if ( protectAttributeNameRegex.test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 ) |
763 | 778 | return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr;
|
764 |
| - } |
765 | 779 |
|
766 | 780 | return fullAttr;
|
767 | 781 | } ) + '>';
|
|
0 commit comments