Skip to content

Fix spreadsheet validation message formatting regression in kendo.format #8326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/kendo.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,35 @@ function pad(number, digits, end) {
kendo.format = function(fmt) {
var values = arguments;

// Fix for spreadsheet validation message regression: detect malformed arguments
// Pattern: kendo.format("Please enter a valid {0} value {1}.", "any", "greater than 10,,10,,number,reject,greaterThan")
// Should be: kendo.format("Please enter a valid {0} value {1}.", "number", "greater than 10")
if (values.length === 3 && typeof values[1] === "string" && typeof values[2] === "string" &&
values[2].indexOf(",,") > -1) {

// Split the malformed second argument
var parts = values[2].split(",");
if (parts.length >= 5) {
// Check if this looks like the validation message pattern
// Find the criteria type by looking for known validation types
var criteriaType = null;
var comparerMessage = parts[0]; // Should be the comparer message

var validationTypes = ["number", "text", "date", "custom", "list"];
for (var i = 0; i < parts.length; i++) {
if (validationTypes.indexOf(parts[i]) > -1) {
criteriaType = parts[i];
break;
}
}

// Only apply fix if we found a valid criteria type
if (criteriaType) {
values = [fmt, criteriaType, comparerMessage];
}
}
}

return fmt.replace(formatRegExp, function(match, index, placeholderFormat) {
var value = values[parseInt(index, 10) + 1];

Expand Down
1 change: 1 addition & 0 deletions tests/test-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"}]}
65 changes: 65 additions & 0 deletions tests/unit/core/format-validation-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Test the fix for the spreadsheet validation message issue

// Import the core to test our fix
import '@progress/kendo-ui/src/kendo.core.js';

describe("kendo.format validation message fix", function() {

it("should handle normal format calls correctly", function() {
const result = kendo.format("Hello {0} {1}", "world", "!");
assert.equal(result, "Hello world !");
});

it("should fix malformed spreadsheet validation messages", function() {
// This is the malformed input that causes the issue
const malformedResult = kendo.format(
"Please enter a valid {0} value {1}.",
"any",
"greater than 10,,10,,number,reject,greaterThan"
);

// Should be fixed to show the correct message
assert.equal(malformedResult, "Please enter a valid number value greater than 10.");
});

it("should handle different criteria types", function() {
const textResult = kendo.format(
"Please enter a valid {0} value {1}.",
"any",
"containing hello,,test,,text,reject,contains"
);

assert.equal(textResult, "Please enter a valid text value containing hello.");
});

it("should handle date validation", function() {
const dateResult = kendo.format(
"Please enter a valid {0} value {1}.",
"any",
"after 2024-01-01,,2024-01-01,,date,reject,greaterThan"
);

assert.equal(dateResult, "Please enter a valid date value after 2024-01-01.");
});

it("should not affect normal format calls with commas", function() {
const normalResult = kendo.format(
"Items: {0}, Count: {1}",
"apple,banana,cherry",
"3"
);

assert.equal(normalResult, "Items: apple,banana,cherry, Count: 3");
});

it("should not affect calls without the specific malformed pattern", function() {
const normalResult = kendo.format(
"Please enter a valid {0} value {1}.",
"number",
"between 1 and 10"
);

assert.equal(normalResult, "Please enter a valid number value between 1 and 10.");
});

});
36 changes: 36 additions & 0 deletions tests/unit/core/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,40 @@ describe("format", function() {
assert.equal(format("{1}foo", 1), "foo");
});

// New tests for the spreadsheet validation message fix
it("fixes malformed spreadsheet validation messages for number criteria", function() {
const result = format("Please enter a valid {0} value {1}.", "any", "greater than 10,,10,,number,reject,greaterThan");
assert.equal(result, "Please enter a valid number value greater than 10.");
});

it("fixes malformed spreadsheet validation messages for text criteria", function() {
const result = format("Please enter a valid {0} value {1}.", "any", "containing hello,,test,,text,reject,contains");
assert.equal(result, "Please enter a valid text value containing hello.");
});

it("fixes malformed spreadsheet validation messages for date criteria", function() {
const result = format("Please enter a valid {0} value {1}.", "any", "after 2024-01-01,,2024-01-01,,date,reject,greaterThan");
assert.equal(result, "Please enter a valid date value after 2024-01-01.");
});

it("fixes malformed spreadsheet validation messages for custom criteria", function() {
const result = format("Please enter a valid {0} value {1}.", "any", "that satisfies formula,,x > 0,,custom,reject,custom");
assert.equal(result, "Please enter a valid custom value that satisfies formula.");
});

it("does not modify normal format calls with commas in arguments", function() {
const result = format("Items: {0}, Count: {1}", "apple,banana,cherry", "3");
assert.equal(result, "Items: apple,banana,cherry, Count: 3");
});

it("does not modify normal validation messages", function() {
const result = format("Please enter a valid {0} value {1}.", "number", "greater than 10");
assert.equal(result, "Please enter a valid number value greater than 10.");
});

it("does not modify format calls that don't match the malformed pattern", function() {
const result = format("Test {0} {1}", "arg1", "arg2,,with,,commas,,but,,not,,validation");
assert.equal(result, "Test arg1 arg2,,with,,commas,,but,,not,,validation");
});

});