Explorar el Código

Correct regular expression to be literal. Extract regexp choice to separate variable.

Mateusz Samsel hace 6 años
padre
commit
7cfdccf1ed
Se han modificado 1 ficheros con 6 adiciones y 4 borrados
  1. 6 4
      packages/ckeditor5-word-count/src/wordcount.js

+ 6 - 4
packages/ckeditor5-word-count/src/wordcount.js

@@ -238,11 +238,13 @@ export default class WordCount extends Plugin {
 		// {M} - A character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.).
 		// {Pd} - Any kind of hyphen or dash.
 		// {Pc} - A punctuation character such as an underscore that connects words.
-		const wordsMatch = regExpFeatureDetection.isUnicodePropertySupported ?
-			txt.match( new RegExp( '[\\p{L}\\p{N}\\p{M}\\p{Pd}\\p{Pc}]+', 'gu' ) ) :
-			txt.match( /[_\-a-zA-Z0-9À-ž]+/gu );
+		const wordsMatchRegExp = regExpFeatureDetection.isUnicodePropertySupported ?
+			/[\p{L}\p{N}\p{M}\p{Pd}\p{Pc}]+/gu :
+			/[_\-a-zA-Z0-9À-ž]+/gu;
 
-		this.words = ( wordsMatch || [] ).length;
+		const detectedWords = txt.match( wordsMatchRegExp ) || [];
+
+		this.words = detectedWords.length;
 
 		this.fire( 'update', {
 			words: this.words,