fix: js string split (#38233)

fix #38229
This commit is contained in:
wxiaoguang
2026-06-27 20:09:01 +08:00
committed by GitHub
parent b565f3e00a
commit 16c3216dc6
4 changed files with 60 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import {registerGlobalInitFunc} from '../../modules/observer.ts';
import {queryElems} from '../../utils/dom.ts';
import {errorMessage} from '../../modules/errors.ts';
import {submitFormFetchAction} from '../common-fetch-action.ts';
import {cutString} from '../../utils/string.ts';
const {appSubUrl} = window.config;
@@ -158,7 +159,7 @@ export class ConfigFormValueMapper {
const apps: Array<{DisplayName: string, OpenURL: string}> = [];
const lines = cfgVal.split('\n');
for (const line of lines) {
let [displayName, openUrl] = line.split('=', 2);
let [displayName, openUrl] = cutString(line, '=');
displayName = displayName.trim();
openUrl = openUrl?.trim() ?? '';
if (!displayName || !openUrl) continue;

View File

@@ -0,0 +1,13 @@
import {cutString} from './string.ts';
test('cutString', () => {
let [before, after, ok] = cutString('a = b = c', '=');
expect(before).toBe('a ');
expect(after).toBe(' b = c');
expect(ok).toBe(true);
[before, after, ok] = cutString(' a ', '=');
expect(before).toBe(' a ');
expect(after).toBe('');
expect(ok).toBe(false);
});

View File

@@ -0,0 +1,5 @@
export function cutString(s: string, sep: string): [string, string, boolean] {
const index = s.indexOf(sep);
if (index === -1) return [s, '', false];
return [s.substring(0, index), s.substring(index + sep.length), true];
}