Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(engine-formula): handle Unicode letters in PROPER (#7927)

白熱0620bb6d5fea
diff --git a/packages/engine-formula/src/functions/text/proper/__tests__/index.spec.ts b/packages/engine-formula/src/functions/text/proper/__tests__/index.spec.ts
index 6a1ebaebac..d0a44dfa42 100644
--- a/packages/engine-formula/src/functions/text/proper/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/text/proper/__tests__/index.spec.ts
@@ -32,6 +32,46 @@ describe('Test proper function', () => {
expect(getObjectValue(result)).toStrictEqual('Univer');
});
+ it.each([
+ ['hans müller-lüdenscheidt', 'Hans Müller-Lüdenscheidt'],
+ ['müller', 'Müller'],
+ ['mu\u0308ller', 'Mu\u0308Ller'],
+ ['élise', 'Élise'],
+ ['e\u0301lise', 'E\u0301Lise'],
+ ['中文abc', '中文abc'],
+ ['abc中文def', 'Abc中文def'],
+ ['ü', 'Ü'],
+ ['straße', 'Straße'],
+ ['αβγ', 'Αβγ'],
+ ['привет', 'Привет'],
+ ['a1b', 'A1B'],
+ ['2-way street', '2-Way Street'],
+ ['o\'NEILL', 'O\'Neill'],
+ ])('Uses Excel letter boundaries for %s', (input, expected) => {
+ const result = testFunction.calculate(StringValueObject.create(input));
+ expect(getObjectValue(result)).toStrictEqual(expected);
+ });
+
+ it('Capitalizes Unicode text in arrays', () => {
+ const text = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['müller', 'élise'],
+ ['ü', '中文abc'],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(text);
+ expect(getObjectValue(result)).toStrictEqual([
+ ['Müller', 'Élise'],
+ ['Ü', '中文abc'],
+ ]);
+ });
+
it('Value is array', () => {
const text = ArrayValueObject.create({
calculateValueList: transformToValueObject([
diff --git a/packages/engine-formula/src/functions/text/proper/index.ts b/packages/engine-formula/src/functions/text/proper/index.ts
index b69d974d2d..16e44fef0b 100644
--- a/packages/engine-formula/src/functions/text/proper/index.ts
+++ b/packages/engine-formula/src/functions/text/proper/index.ts
@@ -45,7 +45,7 @@ export class Proper extends BaseFunction {
const textValue = text.getValue().toLocaleString();
- const result = textValue.toLocaleLowerCase().replace(/(^|\b|\W|\d|_)[a-z]/g, (txt) => txt.toLocaleUpperCase());
+ const result = textValue.toLocaleLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (_, before, letter) => before + letter.toLocaleUpperCase());
return StringValueObject.create(result);
}