Kaynağa Gözat

fix: (select) filter text start with special chars will throw error, close #743

* fix(select): filter text start with special chars

* fix: refix

* test: add test case
格桑 3 yıl önce
ebeveyn
işleme
857e935123

+ 1 - 1
packages/semi-foundation/utils/getHighlight.ts

@@ -152,7 +152,7 @@ const fillInChunks = ({ chunksToHighlight, totalLength }: { chunksToHighlight: C
  */
  */
 
 
 const findAll = ({
 const findAll = ({
-    autoEscape,
+    autoEscape = true,
     caseSensitive = false,
     caseSensitive = false,
     searchWords,
     searchWords,
     sourceString
     sourceString

+ 16 - 0
packages/semi-ui/select/__test__/select.test.js

@@ -504,6 +504,22 @@ describe('Select', () => {
         expect(optionList.at(0).text()).toEqual('Abc');
         expect(optionList.at(0).text()).toEqual('Abc');
     });
     });
 
 
+    it('filter = true,label includes regex special character and key it at first', () => {
+        let props = {
+            filter: true,
+            optionList: [{label: 'label++',value: ''}]
+        };
+        const select = getSelect(props);
+        // click to show input
+        select.find(`.${BASE_CLASS_PREFIX}-select`).simulate('click', {});
+        let inputValue = '+';
+        let event = { target: { value: inputValue } };
+        select.find('input').simulate('change', event);
+        let optionList = select.find(`.${BASE_CLASS_PREFIX}-select-option-list`).children();
+        expect(optionList.length).toEqual(1);
+        expect(optionList.at(0).text()).toEqual('label++');
+    });
+
     it('filter = custom function', () => {
     it('filter = custom function', () => {
         let customFilter = (sugInput, option) => {
         let customFilter = (sugInput, option) => {
             return option.label == 'Hotsoon';
             return option.label == 'Hotsoon';