mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-12 16:15:02 +03:00
fix(frontend): keep node-reported text out of i18next's nesting parser
The SPA initialised i18next with nesting on, though no locale uses
$t(...), so its nesting regex, exponential on an unclosed "$t(", ran
over every missing key and interpolated value, including the status and
name a node reports for its sub-nodes. One crafted status froze the
Nodes page.
Nesting is switched off for every i18next instance the project creates,
an unknown status renders as Unknown instead of being used as a key,
and a sub-node is never named as the parent it is reached through.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import i18next from 'i18next';
|
||||
import type { InterpolationOptions } from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
import { LanguageManager } from '@/utils';
|
||||
@@ -8,6 +9,16 @@ import enUS from '../../../internal/web/translation/en-US.json';
|
||||
|
||||
const FALLBACK = 'en-US';
|
||||
|
||||
// No locale uses $t(...) nesting, and its regex backtracks exponentially on an unclosed
|
||||
// "$t(" in untrusted text (node-reported names, remarks); no off switch, so never match.
|
||||
export const INTERPOLATION: InterpolationOptions = {
|
||||
escapeValue: false,
|
||||
prefix: '{',
|
||||
suffix: '}',
|
||||
nestingPrefix: '',
|
||||
nestingPrefixEscaped: '(?!)',
|
||||
};
|
||||
|
||||
const lazyModules = import.meta.glob([
|
||||
'../../../internal/web/translation/*.json',
|
||||
'!../../../internal/web/translation/en-US.json',
|
||||
@@ -30,7 +41,7 @@ export async function readyI18n(scope: LanguageScope = 'panel') {
|
||||
lng: active,
|
||||
fallbackLng: FALLBACK,
|
||||
resources: { [FALLBACK]: { translation: enUS } },
|
||||
interpolation: { escapeValue: false, prefix: '{', suffix: '}' },
|
||||
interpolation: INTERPOLATION,
|
||||
returnNull: false,
|
||||
});
|
||||
if (active !== FALLBACK) {
|
||||
|
||||
Reference in New Issue
Block a user