From 2ab130cbafe9489aa2aec30250ae50b7e111f8f0 Mon Sep 17 00:00:00 2001 From: Angsar Date: Sat, 14 Feb 2026 15:47:02 +0000 Subject: [PATCH] [all] Fix bug 79936 (#1925) [all] Fix bug 79936 Co-authored-by: Angsar Co-committed-by: Angsar --- cell/apiBuilder.js | 4 ++-- cell/model/DataValidation.js | 23 +++++++++++++++-------- tests/cell/js-api/api-validation.js | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 3e231a8fb6..a382341fa9 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -20132,7 +20132,7 @@ let formula1 = validation.getFormula1(); let worksheet = this.range && this.range.range && this.range.range.worksheet; if (formula1 && worksheet) { - formula1 = formula1.clone(); + formula1 = formula1.clone(true); formula1.correctToInterface(worksheet, validation); } return formula1 ? formula1.asc_getValue() : ""; @@ -20153,7 +20153,7 @@ let formula2 = validation.getFormula2(); let worksheet = this.range && this.range.range && this.range.range.worksheet; if (formula2 && worksheet) { - formula2 = formula2.clone(); + formula2 = formula2.clone(true); formula2.correctToInterface(worksheet, validation); } return formula2 ? formula2.asc_getValue() : ""; diff --git a/cell/model/DataValidation.js b/cell/model/DataValidation.js index 74afa15977..aaa8b61834 100644 --- a/cell/model/DataValidation.js +++ b/cell/model/DataValidation.js @@ -75,10 +75,13 @@ this._formula.buildDependencies(); } }; - CDataFormula.prototype.clone = function () { + CDataFormula.prototype.clone = function (fullClone) { var res = new CDataFormula(); res.text = this.text; //this._formula = null; + if (fullClone && this._formula) { + res._formula = this._formula.clone(); + } return res; }; CDataFormula.prototype.onFormulaEvent = function (type, eventData) { @@ -126,10 +129,13 @@ isNum: isNum(this.text), } - const normalizeText = function (data) { - const isQuote = typeof data.val === "string" && data.val.length >=2 && data.val[0] === '"'; + const isQuoted = function (data) { + return typeof data.val === "string" && data.val.length >=2 && data.val[0] === '"'; + } - if (isQuote) { + const normalizeText = function (data, wasQuoted) { + + if (wasQuoted) { let _val = data.val; _val = _val.slice(1, -1); @@ -181,13 +187,14 @@ } // fix the text from quotes - data = normalizeText(data) + const wasQuoted = isQuoted(data); + data = normalizeText(data, wasQuoted); if (data.isNum) { fromNumberToString(data); - } else if (oValidation.type === Asc.EDataValidationType.List) { - toListPreview(data); } else { - if (this && this._formula) { + if (wasQuoted && oValidation.type === Asc.EDataValidationType.List) { + toListPreview(data); + } else if (this && this._formula) { //если формула содержит ссылки на диапазоны, то в зависимости от активной области нужно их сдвинуть var offset = oValidation.calculateOffset(ws); if (offset) { diff --git a/tests/cell/js-api/api-validation.js b/tests/cell/js-api/api-validation.js index 2100514b43..58a9d5a03e 100644 --- a/tests/cell/js-api/api-validation.js +++ b/tests/cell/js-api/api-validation.js @@ -129,7 +129,7 @@ $(function () { const src = ws.GetRange("F1:F2"); src.SetValue('x'); const r3 = ws.GetRange("G1:G2"); r3.GetValidation().Add('xlValidateList', 'xlValidAlertWarning', undefined, ws.GetRange('F1:F2')); - assert.strictEqual(r3.GetValidation().GetFormula1(), 'F1:F2', "Formula1 from ApiRange address"); + assert.strictEqual(r3.GetValidation().GetFormula1(), '=F1:F2', "Formula1 from ApiRange address"); }); QUnit.test("Add fails when type is invalid", function (assert) { @@ -410,7 +410,7 @@ $(function () { const v = r.GetValidation(); assert.strictEqual(v.GetType(), "xlValidateList", "Type"); - assert.strictEqual(v.GetFormula1(), "M1:M2", "Formula1 returns range address (no quotes, no '=')"); + assert.strictEqual(v.GetFormula1(), "=M1:M2", "Formula1 returns range address (no quotes, no '=')"); }); QUnit.test("xlValidateDate: Greater than 01/31/2027 => stored numerically (no '=' drift)", function (assert) {