github-advanced-security[bot] commented on code in PR #75326:
URL: https://github.com/apache/airflow/pull/75326#discussion_r4338905029
##########
airflow-core/src/airflow/ui/src/i18n/locales.test.ts:
##########
@@ -52,6 +52,62 @@
flattenStrings(namespaces, lng),
);
+// Every static key the UI passes to `translate(...)` has to exist in the en
bundles, otherwise
+// i18next falls back to rendering the key itself and the user sees something
like
+// "pools.form.nameMaxLength" where a sentence belongs.
+const sourceFiles: Record<string, string> =
import.meta.glob("../**/*.{ts,tsx}", {
+ eager: true,
+ import: "default",
+ query: "?raw",
+});
+
+// The namespaces a file loads, in the order i18next searches them.
+const USE_TRANSLATION =
/useTranslation\(\s*(?<names>\[[^\]]*\]|"[^"]+"|'[^']+')/gu;
+// Only literal keys; anything interpolated is resolved at runtime and cannot
be checked here.
+const TRANSLATE_CALL = /\b(?:translate|t)\(\s*"(?<key>[^"{}`$]+)"/gu;
+const QUOTED = /["'](?<name>[^"']+)["']/gu;
+
+const namespacesOf = (source: string): Array<string> =>
+ [...source.matchAll(USE_TRANSLATION)].flatMap((match) =>
+ [...(match.groups?.names ?? "").matchAll(QUOTED)].map((quoted) =>
quoted.groups?.name ?? ""),
+ );
+
+const findUnresolvedKeys = (file: string, source: string, instance: i18n):
Array<string> => {
+ const namespaces = namespacesOf(source);
+
+ if (namespaces.length === 0) {
+ return [];
+ }
+
+ // i18next falls back to defaultNS, so it is always a candidate.
+ const candidates = [...new Set([...namespaces, i18nBaseOptions.defaultNS])];
+
+ const unresolved = [...source.matchAll(TRANSLATE_CALL)]
+ .map((match) => match.groups?.key ?? "")
+ .filter((key) => {
+ const prefixed = key.includes(":") ? [key] : candidates.map((ns) =>
`${ns}:${key}`);
+
+ // `count` lets i18next resolve plural-only keys such as `foo_one` /
`foo_other`.
+ return !prefixed.some((candidate) => instance.exists(candidate, { count:
1 }));
+ });
+
+ return unresolved.map((key) => `${file.replace("../", "")}: ${key}`);
Review Comment:
## CodeQL / Incomplete string escaping or encoding
This replaces only the first occurrence of "../".
[Show more
details](https://github.com/apache/airflow/security/code-scanning/681)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]