File tree Expand file tree Collapse file tree 3 files changed +7
-6
lines changed
Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ import emitter from 'element-ui/src/mixins/emitter';
7070import Locale from ' element-ui/src/mixins/locale' ;
7171import { t } from ' element-ui/src/locale' ;
7272import debounce from ' throttle-debounce/debounce' ;
73- import { generateId } from ' element-ui/src/utils/util' ;
73+ import { generateId , escapeRegexpString } from ' element-ui/src/utils/util' ;
7474
7575const popperMixin = {
7676 props: {
@@ -337,7 +337,8 @@ export default {
337337 }
338338
339339 let filteredFlatOptions = flatOptions .filter (optionsStack => {
340- return optionsStack .some (option => new RegExp (value, ' i' ).test (option[this .labelKey ]));
340+ return optionsStack .some (option => new RegExp (escapeRegexpString (value), ' i' )
341+ .test (option[this .labelKey ]));
341342 });
342343
343344 if (filteredFlatOptions .length > 0 ) {
Original file line number Diff line number Diff line change 1717
1818<script type="text/babel">
1919 import Emitter from ' element-ui/src/mixins/emitter' ;
20- import { getValueByPath } from ' element-ui/src/utils/util' ;
20+ import { getValueByPath , escapeRegexpString } from ' element-ui/src/utils/util' ;
2121
2222 export default {
2323 mixins: [Emitter],
129129 },
130130
131131 queryChange (query ) {
132- // query 里如果有正则中的特殊字符,需要先将这些字符转义
133- let parsedQuery = String (query).replace (/ (\^ | \( | \) | \[ | \] | \$ | \* | \+ | \. | \? | \\ | \{ | \} | \| )/ g , ' \\ $1' );
134- this .visible = new RegExp (parsedQuery, ' i' ).test (this .currentLabel ) || this .created ;
132+ this .visible = new RegExp (escapeRegexpString (query), ' i' ).test (this .currentLabel ) || this .created ;
135133 if (! this .visible ) {
136134 this .select .filteredOptionsCount -- ;
137135 }
Original file line number Diff line number Diff line change @@ -82,3 +82,5 @@ export const valueEquals = (a, b) => {
8282 }
8383 return true ;
8484} ;
85+
86+ export const escapeRegexpString = value => String ( value ) . replace ( / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g, '\\$&' ) ;
You can’t perform that action at this time.
0 commit comments