[bugfix] Use re2 syntax for regex validation (#2978)

This commit is contained in:
tobi 2024-06-08 14:32:28 +02:00 committed by GitHub
parent ce3b8aacf7
commit 048339a6aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 5 deletions

View File

@ -27,6 +27,7 @@
"photoswipe-dynamic-caption-plugin": "^1.2.7",
"plyr": "^3.7.8",
"psl": "^1.9.0",
"re2js": "^0.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.3",

View File

@ -24,6 +24,7 @@ import useFormSubmit from "../../../lib/form/submit";
import { TextInput } from "../../../components/form/inputs";
import MutationButton from "../../../components/form/mutation-button";
import { PermType } from "../../../lib/types/perm";
import { RE2JS } from "re2js";
export default function HeaderPermCreateForm({ permType }: { permType: PermType }) {
const form = {
@ -56,7 +57,7 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType
// Ensure regex compiles.
try {
new RegExp(val);
RE2JS.compile(val);
} catch (e) {
return e;
}
@ -116,14 +117,14 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType
field={form.regex}
label={
<>
HTTP Header Value Regex&nbsp;
HTTP Header Value RE2 Regex&nbsp;
<a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions"
href="https://github.com/google/re2/wiki/Syntax"
target="_blank"
className="docslink"
rel="noreferrer"
>
Learn more about regular expressions (opens in a new tab)
Learn more about RE2 regular expressions (opens in a new tab)
</a>
</>
}

View File

@ -154,7 +154,7 @@ function PermDeets({
// with this regular expression prepopulated.
const testParams = new URLSearchParams();
testParams.set("regex", perm.regex);
testParams.set("flags", "g");
testParams.set("flags", "gm");
testParams.set("testString", testString);
const regexLink = `https://regex101.com/?${testParams.toString()}`;

View File

@ -5513,6 +5513,11 @@ raw-body@~1.1.0:
bytes "1"
string_decoder "0.10"
re2js@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/re2js/-/re2js-0.4.1.tgz#74a87a90b79ab5dc1effed818151354c8faccb3d"
integrity sha512-Kxb+OKXrEPowP4bXAF07NDXtgYX07S8HeVGgadx5/D/R41LzWg1kgTD2szIv2iHJM3vrAPnDKaBzfUE/7QWX9w==
react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"