Skip to content

Commit ff56bd5

Browse files
committed
correct value formatting in violation messages
Commit symfony/symfony@97243bc changed formatting of violation message parameters. (since Symfony v2.3.19, v2.4.9, v2.5.3)
1 parent 1c0d120 commit ff56bd5

31 files changed

Lines changed: 168 additions & 107 deletions

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ language: php
33
php: [5.3]
44

55
env:
6-
- SF_VERSION='~2.3.0'
7-
- SF_VERSION='~2.4.0'
8-
- SF_VERSION='>=2.5,<2.5.3'
6+
- SF_VERSION='~2.3.0,>=2.3.19'
7+
- SF_VERSION='~2.4.0,>=2.4.9'
8+
- SF_VERSION='~2.5.0,>=2.5.3,<=2.5.4'
99

1010
before_script:
1111
- export WEB_FIXTURES_HOST=http://localhost/index.php

Resources/public/js/FpJsFormValidator.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,31 @@ var FpJsBaseConstraint = {
335335
}
336336

337337
return realMsg;
338+
},
339+
340+
formatValue: function (value) {
341+
switch (Object.prototype.toString.call(value)) {
342+
case '[object Date]':
343+
return value.format('Y-m-d H:i:s');
344+
345+
case '[object Object]':
346+
return 'object';
347+
348+
case '[object Array]':
349+
return 'array';
350+
351+
case '[object String]':
352+
return '"' + value + '"';
353+
354+
case '[object Null]':
355+
return 'null';
356+
357+
case '[object Boolean]':
358+
return value ? 'true' : 'false';
359+
360+
default:
361+
return String(value);
362+
}
338363
}
339364
};
340365

Resources/public/js/constraints/Blank.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function SymfonyComponentValidatorConstraintsBlank() {
1212
var f = FpJsFormValidator;
1313

1414
if (!f.isValueEmty(value)) {
15-
errors.push(this.message.replace('{{ value }}', String(value)));
15+
errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue(value)));
1616
}
1717

1818
return errors;

Resources/public/js/constraints/Choice.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function SymfonyComponentValidatorConstraintsChoice() {
2929
if (this.multiple) {
3030
if (invalidCnt) {
3131
while (invalidCnt--) {
32-
errors.push(this.multipleMessage.replace('{{ value }}', String(invalidList[invalidCnt])));
32+
errors.push(this.multipleMessage.replace(
33+
'{{ value }}',
34+
FpJsBaseConstraint.formatValue(invalidList[invalidCnt])
35+
));
3336
}
3437
}
3538
if (!isNaN(this.min) && value.length < this.min) {
@@ -40,7 +43,10 @@ function SymfonyComponentValidatorConstraintsChoice() {
4043
}
4144
} else if (invalidCnt) {
4245
while (invalidCnt--) {
43-
errors.push(this.message.replace('{{ value }}', String(invalidList[invalidCnt])));
46+
errors.push(this.message.replace(
47+
'{{ value }}',
48+
FpJsBaseConstraint.formatValue(invalidList[invalidCnt])
49+
));
4450
}
4551
}
4652

@@ -53,12 +59,12 @@ function SymfonyComponentValidatorConstraintsChoice() {
5359

5460
this.minMessage = FpJsBaseConstraint.prepareMessage(
5561
this.minMessage,
56-
{'{{ limit }}': this.min},
62+
{'{{ limit }}': FpJsBaseConstraint.formatValue(this.min)},
5763
this.min
5864
);
5965
this.maxMessage = FpJsBaseConstraint.prepareMessage(
6066
this.maxMessage,
61-
{'{{ limit }}': this.max},
67+
{'{{ limit }}': FpJsBaseConstraint.formatValue(this.max)},
6268
this.max
6369
);
6470
};

Resources/public/js/constraints/Count.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ function SymfonyComponentValidatorConstraintsCount() {
4242

4343
this.minMessage = FpJsBaseConstraint.prepareMessage(
4444
this.minMessage,
45-
{'{{ limit }}': this.min},
45+
{'{{ limit }}': FpJsBaseConstraint.formatValue(this.min)},
4646
this.min
4747
);
4848
this.maxMessage = FpJsBaseConstraint.prepareMessage(
4949
this.maxMessage,
50-
{'{{ limit }}': this.max},
50+
{'{{ limit }}': FpJsBaseConstraint.formatValue(this.max)},
5151
this.max
5252
);
5353
this.exactMessage = FpJsBaseConstraint.prepareMessage(
5454
this.exactMessage,
55-
{'{{ limit }}': this.min},
55+
{'{{ limit }}': FpJsBaseConstraint.formatValue(this.min)},
5656
this.min
5757
);
5858
}

Resources/public/js/constraints/Date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function SymfonyComponentValidatorConstraintsDate() {
1313
var f = FpJsFormValidator;
1414

1515
if (!f.isValueEmty(value) && !regexp.test(value)) {
16-
errors.push(this.message.replace('{{ value }}', String(value)));
16+
errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue(value)));
1717
}
1818

1919
return errors;

Resources/public/js/constraints/DateTime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function SymfonyComponentValidatorConstraintsDateTime() {
1313
var f = FpJsFormValidator;
1414

1515
if (!f.isValueEmty(value) && !regexp.test(value)) {
16-
errors.push(this.message.replace('{{ value }}', String(value)));
16+
errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue(value)));
1717
}
1818

1919
return errors;

Resources/public/js/constraints/Email.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function SymfonyComponentValidatorConstraintsEmail() {
1313
var f = FpJsFormValidator;
1414

1515
if (!f.isValueEmty(value) && !regexp.test(value)) {
16-
errors.push(this.message.replace('{{ value }}', String(value)));
16+
errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue(value)));
1717
}
1818

1919
return errors;

Resources/public/js/constraints/EqualTo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function SymfonyComponentValidatorConstraintsEqualTo() {
1515
if (!f.isValueEmty(value) && this.value != value) {
1616
errors.push(
1717
this.message
18-
.replace('{{ value }}', String(value))
19-
.replace('{{ compared_value }}', String(this.value))
20-
.replace('{{ compared_value_type }}', String(this.value))
18+
.replace('{{ value }}', FpJsBaseConstraint.formatValue(value))
19+
.replace('{{ compared_value }}', FpJsBaseConstraint.formatValue(this.value))
20+
.replace('{{ compared_value_type }}', FpJsBaseConstraint.formatValue(this.value))
2121
);
2222
}
2323

Resources/public/js/constraints/False.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function SymfonyComponentValidatorConstraintsFalse() {
1010
this.validate = function (value) {
1111
var errors = [];
1212
if ('' !== value && false !== value) {
13-
errors.push(this.message.replace('{{ value }}', value));
13+
errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue(value)));
1414
}
1515

1616
return errors;

0 commit comments

Comments
 (0)