1/* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/* 17 * @tc.name:property detector 18 * @tc.desc:test property detector 19 * @tc.type: FUNC 20 * @tc.require: issueI83B0E 21 */ 22 23let str = '这是一段原始文本,"3c这要替换4d"!'; 24let regexp = /([0-9])([a-z])/g 25let newStr1 = str.replace(regexp, "$1" ); 26print(newStr1) 27print(ArkTools.isRegExpReplaceDetectorValid()) 28 29let p = RegExp.prototype 30let unused = p[Symbol.replace] 31print(ArkTools.isRegExpReplaceDetectorValid()) 32 33p["replace"] = function () {return "abc"} 34print(ArkTools.isRegExpReplaceDetectorValid()) 35 36regexp.__proto__ = {} 37let newStr2 = str.replace(regexp, "$2" ); 38print(newStr2) 39print(ArkTools.isRegExpReplaceDetectorValid()) 40 41// resume regexp.__proto__ 42regexp.__proto__ = p 43p[Symbol.replace] = function () {return "aaa"} 44let newStr3 = str.replace(regexp, "$3" ); 45print(newStr3) 46print(ArkTools.isRegExpReplaceDetectorValid()) 47 48p[Symbol.replace] = function () {return 4} 49let newStr4 = str.replace( /([0-9])([a-z])/g,"$4" ); 50print(newStr4) 51print(ArkTools.isRegExpReplaceDetectorValid()) 52