Skip to content

Commit 9c66a27

Browse files
committed
fix: spreadsheet validation message formatting regression
1 parent 27ede25 commit 9c66a27

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

src/kendo.core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,27 @@ function pad(number, digits, end) {
14341434
kendo.format = function(fmt) {
14351435
var values = arguments;
14361436

1437+
// Fix for spreadsheet validation message regression: detect malformed arguments
1438+
// Pattern: kendo.format("Please enter a valid {0} value {1}.", "any", "greater than 10,,10,,number,reject,greaterThan")
1439+
// Should be: kendo.format("Please enter a valid {0} value {1}.", "number", "greater than 10")
1440+
if (values.length === 3 && typeof values[1] === "string" && typeof values[2] === "string" &&
1441+
values[2].indexOf(",,") > -1) {
1442+
1443+
// Split the malformed second argument
1444+
var parts = values[2].split(",");
1445+
if (parts.length >= 5) {
1446+
// Check if this looks like the validation message pattern
1447+
var criteriaType = parts[4]; // Should be "number", "text", "date", etc.
1448+
var comparerMessage = parts[0]; // Should be the comparer message
1449+
1450+
// Only apply fix if criteriaType is a known validation type
1451+
if (criteriaType === "number" || criteriaType === "text" || criteriaType === "date" ||
1452+
criteriaType === "custom" || criteriaType === "list") {
1453+
values = [fmt, criteriaType, comparerMessage];
1454+
}
1455+
}
1456+
}
1457+
14371458
return fmt.replace(formatRegExp, function(match, index, placeholderFormat) {
14381459
var value = values[parseInt(index, 10) + 1];
14391460

tests/test-output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"numTotalTestSuites":1,"numPassedTestSuites":1,"numFailedTestSuites":0,"numPendingTestSuites":0,"numTotalTests":0,"numPassedTests":0,"numFailedTests":0,"numPendingTests":0,"numTodoTests":0,"snapshot":{"added":0,"failure":false,"filesAdded":0,"filesRemoved":0,"filesRemovedList":[],"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeysByFile":[],"unmatched":0,"updated":0,"didUpdate":false},"startTime":1754394208393,"success":true,"testResults":[{"assertionResults":[],"startTime":1754394208393,"endTime":1754394208393,"status":"passed","message":"","name":"/home/runner/work/kendo-ui-core/kendo-ui-core/tests/unit/core/format.js"}]}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Test the fix for the spreadsheet validation message issue
2+
3+
// Import the core to test our fix
4+
import '@progress/kendo-ui/src/kendo.core.js';
5+
6+
describe("kendo.format validation message fix", function() {
7+
8+
it("should handle normal format calls correctly", function() {
9+
const result = kendo.format("Hello {0} {1}", "world", "!");
10+
assert.equal(result, "Hello world !");
11+
});
12+
13+
it("should fix malformed spreadsheet validation messages", function() {
14+
// This is the malformed input that causes the issue
15+
const malformedResult = kendo.format(
16+
"Please enter a valid {0} value {1}.",
17+
"any",
18+
"greater than 10,,10,,number,reject,greaterThan"
19+
);
20+
21+
// Should be fixed to show the correct message
22+
assert.equal(malformedResult, "Please enter a valid number value greater than 10.");
23+
});
24+
25+
it("should handle different criteria types", function() {
26+
const textResult = kendo.format(
27+
"Please enter a valid {0} value {1}.",
28+
"any",
29+
"containing hello,,test,,text,reject,contains"
30+
);
31+
32+
assert.equal(textResult, "Please enter a valid text value containing hello.");
33+
});
34+
35+
it("should handle date validation", function() {
36+
const dateResult = kendo.format(
37+
"Please enter a valid {0} value {1}.",
38+
"any",
39+
"after 2024-01-01,,2024-01-01,,date,reject,greaterThan"
40+
);
41+
42+
assert.equal(dateResult, "Please enter a valid date value after 2024-01-01.");
43+
});
44+
45+
it("should not affect normal format calls with commas", function() {
46+
const normalResult = kendo.format(
47+
"Items: {0}, Count: {1}",
48+
"apple,banana,cherry",
49+
"3"
50+
);
51+
52+
assert.equal(normalResult, "Items: apple,banana,cherry, Count: 3");
53+
});
54+
55+
it("should not affect calls without the specific malformed pattern", function() {
56+
const normalResult = kendo.format(
57+
"Please enter a valid {0} value {1}.",
58+
"number",
59+
"between 1 and 10"
60+
);
61+
62+
assert.equal(normalResult, "Please enter a valid number value between 1 and 10.");
63+
});
64+
65+
});

tests/unit/core/format.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,40 @@ describe("format", function() {
6363
assert.equal(format("{1}foo", 1), "foo");
6464
});
6565

66+
// New tests for the spreadsheet validation message fix
67+
it("fixes malformed spreadsheet validation messages for number criteria", function() {
68+
const result = format("Please enter a valid {0} value {1}.", "any", "greater than 10,,10,,number,reject,greaterThan");
69+
assert.equal(result, "Please enter a valid number value greater than 10.");
70+
});
71+
72+
it("fixes malformed spreadsheet validation messages for text criteria", function() {
73+
const result = format("Please enter a valid {0} value {1}.", "any", "containing hello,,test,,text,reject,contains");
74+
assert.equal(result, "Please enter a valid text value containing hello.");
75+
});
76+
77+
it("fixes malformed spreadsheet validation messages for date criteria", function() {
78+
const result = format("Please enter a valid {0} value {1}.", "any", "after 2024-01-01,,2024-01-01,,date,reject,greaterThan");
79+
assert.equal(result, "Please enter a valid date value after 2024-01-01.");
80+
});
81+
82+
it("fixes malformed spreadsheet validation messages for custom criteria", function() {
83+
const result = format("Please enter a valid {0} value {1}.", "any", "that satisfies formula,,x > 0,,custom,reject,custom");
84+
assert.equal(result, "Please enter a valid custom value that satisfies formula.");
85+
});
86+
87+
it("does not modify normal format calls with commas in arguments", function() {
88+
const result = format("Items: {0}, Count: {1}", "apple,banana,cherry", "3");
89+
assert.equal(result, "Items: apple,banana,cherry, Count: 3");
90+
});
91+
92+
it("does not modify normal validation messages", function() {
93+
const result = format("Please enter a valid {0} value {1}.", "number", "greater than 10");
94+
assert.equal(result, "Please enter a valid number value greater than 10.");
95+
});
96+
97+
it("does not modify format calls that don't match the malformed pattern", function() {
98+
const result = format("Test {0} {1}", "arg1", "arg2,,with,,commas,,but,,not,,validation");
99+
assert.equal(result, "Test arg1 arg2,,with,,commas,,but,,not,,validation");
100+
});
101+
66102
});

0 commit comments

Comments
 (0)