|
| 1 | +/* |
| 2 | +Copyright 2025 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
1 | 17 | import * as utils from "../test-utils/test-utils";
|
2 | 18 | import { type IActionsObject, PushProcessor } from "../../src/pushprocessor";
|
3 | 19 | import {
|
@@ -1004,3 +1020,25 @@ describe("rewriteDefaultRules", () => {
|
1004 | 1020 | ]);
|
1005 | 1021 | });
|
1006 | 1022 | });
|
| 1023 | + |
| 1024 | +describe("getPushRuleGlobRegex", () => { |
| 1025 | + it("should not confuse flags in cache", () => { |
| 1026 | + const pattern = "Test"; |
| 1027 | + const regex1 = PushProcessor.getPushRuleGlobRegex(pattern, false, "i"); |
| 1028 | + const regex2 = PushProcessor.getPushRuleGlobRegex(pattern, false, "g"); |
| 1029 | + const regex3 = PushProcessor.getPushRuleGlobRegex(pattern, false, "i"); |
| 1030 | + |
| 1031 | + expect(regex1.flags).toBe("i"); |
| 1032 | + expect(regex2.flags).toBe("g"); |
| 1033 | + |
| 1034 | + expect(regex1).not.toEqual(regex2); |
| 1035 | + expect(regex1).toEqual(regex3); |
| 1036 | + }); |
| 1037 | + |
| 1038 | + it("should not include word boundary in match", () => { |
| 1039 | + const pattern = "@room"; |
| 1040 | + const regex = PushProcessor.getPushRuleGlobRegex(pattern, true); |
| 1041 | + const input = "Foo @room Bar"; |
| 1042 | + expect(input.split(regex)).toEqual(["Foo ", "@room", " Bar"]); |
| 1043 | + }); |
| 1044 | +}); |
0 commit comments