mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1863770 - Check locale string whether it has null character. r=platform-i18n-reviewers,dminor
If locale string has null character, we should ignore it. Because it is invalid tag. Differential Revision: https://phabricator.services.mozilla.com/D218807
This commit is contained in:
parent
e83e3e8e18
commit
fcedf0237c
29
dom/html/crashtests/1863770.html
Normal file
29
dom/html/crashtests/1863770.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html class="reftest-wait">
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const table = document.getElementById('table');
|
||||
const caption = document.createElement('caption');
|
||||
const anchor = document.createElement('a');
|
||||
const span = document.createElement('span');
|
||||
const input = document.createElement('input');
|
||||
span.setAttribute('lang', '\0');
|
||||
input.setAttribute('type', 'number');
|
||||
input.setAttribute('value', 119);
|
||||
anchor.appendChild(input);
|
||||
span.appendChild(anchor);
|
||||
caption.appendChild(span);
|
||||
table.appendChild(caption);
|
||||
setTimeout(() => {
|
||||
const input2 = document.createElement('input');
|
||||
input2.setAttribute('type', 'number');
|
||||
input2.setAttribute('value', "+");
|
||||
span.appendChild(input2);
|
||||
input2.valueAsDecimal;
|
||||
|
||||
document.documentElement.removeAttribute("class");
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
<table id="table"></table>
|
||||
</html>
|
@ -97,3 +97,4 @@ skip-if(Android) load 1787671.html # printPreview doesn't work on android
|
||||
load 1789475.html
|
||||
load 1801380.html
|
||||
load 1840088.html
|
||||
load 1863770.html
|
||||
|
@ -6,12 +6,13 @@
|
||||
namespace mozilla::intl {
|
||||
|
||||
/*static*/ Result<UniquePtr<NumberParser>, ICUError> NumberParser::TryCreate(
|
||||
const char* aLocale, bool aUseGrouping) {
|
||||
std::string_view aLocale, bool aUseGrouping) {
|
||||
UniquePtr<NumberParser> nf = MakeUnique<NumberParser>();
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
nf->mNumberFormat =
|
||||
unum_open(UNUM_DECIMAL, nullptr, 0, aLocale, nullptr, &status);
|
||||
unum_open(UNUM_DECIMAL, nullptr, 0, AssertNullTerminatedString(aLocale),
|
||||
nullptr, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class NumberParser {
|
||||
* provided options.
|
||||
*/
|
||||
static Result<UniquePtr<NumberParser>, ICUError> TryCreate(
|
||||
const char* aLocale, bool aUseGrouping);
|
||||
std::string_view aLocale, bool aUseGrouping);
|
||||
|
||||
NumberParser() : mNumberFormat(nullptr) {};
|
||||
NumberParser(const NumberParser&) = delete;
|
||||
|
@ -87,6 +87,9 @@ bool ICUUtils::LocalizeNumber(double aValue,
|
||||
auto& formatter = sCache->LookupOrInsertWith(langTag, [&] {
|
||||
nsAutoCString tag;
|
||||
langTag->ToUTF8String(tag);
|
||||
if (tag.FindChar('\0') != kNotFound) {
|
||||
return UniquePtr<intl::NumberFormat>();
|
||||
}
|
||||
return intl::NumberFormat::TryCreate(tag, options).unwrapOr(nullptr);
|
||||
});
|
||||
if (!formatter) {
|
||||
@ -122,8 +125,11 @@ double ICUUtils::ParseNumber(const nsAString& aValue,
|
||||
auto& parser = sCache->LookupOrInsertWith(langTag, [&] {
|
||||
nsAutoCString tag;
|
||||
langTag->ToUTF8String(tag);
|
||||
if (tag.FindChar('\0') != kNotFound) {
|
||||
return UniquePtr<intl::NumberParser>();
|
||||
}
|
||||
return intl::NumberParser::TryCreate(
|
||||
tag.get(), StaticPrefs::dom_forms_number_grouping())
|
||||
tag, StaticPrefs::dom_forms_number_grouping())
|
||||
.unwrapOr(nullptr);
|
||||
});
|
||||
if (!parser) {
|
||||
|
Loading…
Reference in New Issue
Block a user