mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1896923 - Use normalize-newlines algorithm for setCustomValidity r=emilio
This is for https://github.com/whatwg/html/pull/10350 Differential Revision: https://phabricator.services.mozilla.com/D210688
This commit is contained in:
parent
896ae1534e
commit
d9ab1cd36a
@ -9,6 +9,7 @@
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
@ -59,7 +60,9 @@ bool ConstraintValidation::CheckValidity() {
|
||||
ConstraintValidation::ConstraintValidation() = default;
|
||||
|
||||
void ConstraintValidation::SetCustomValidity(const nsAString& aError) {
|
||||
mCustomValidity.Assign(aError);
|
||||
nsAutoString error(aError);
|
||||
nsContentUtils::PlatformToDOMLineBreaks(error);
|
||||
mCustomValidity.Assign(error);
|
||||
SetValidityState(VALIDITY_STATE_CUSTOM_ERROR, !mCustomValidity.IsEmpty());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<form>
|
||||
<input id="email" required>
|
||||
</form>
|
||||
<script>
|
||||
test(function() {
|
||||
const input = document.getElementById("email");
|
||||
input.setCustomValidity("First line\rSecond line\r\nThird line\nFourth line");
|
||||
assert_equals(input.validationMessage, "First line\nSecond line\nThird line\nFourth line");
|
||||
}, "setCustomValidity should normalize newlines from the given error message");
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user