v8-enhance-Date-parser-to-take-Unicode-SPACE.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 81dd64c3705f89653859a5d0001dd0ca983a92e2 Mon Sep 17 00:00:00 2001
  2. From: Frank Tang <ftang@chromium.org>
  3. Date: Wed, 16 Nov 2022 09:18:45 -0800
  4. Subject: [PATCH] [intl] Enhance Date parser to take Unicode SPACE
  5. This is needed to prepare for the landing of ICU72.
  6. Allow U+202F in the Date String, which the toLocaleString("en-US")
  7. will generate w/ ICU72.
  8. Bug: v8:13494
  9. Change-Id: I41b83c4094ce3d0737a72dcd6310b52c68fdcdca
  10. Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4027341
  11. Reviewed-by: Yang Guo <yangguo@chromium.org>
  12. Reviewed-by: Jungshik Shin <jshin@chromium.org>
  13. Commit-Queue: Frank Tang <ftang@chromium.org>
  14. Cr-Commit-Position: refs/heads/main@{#84308}
  15. (cherry picked from commit 2ada52cffbff11074abfaac18938bf02d85454f5)
  16. ---
  17. src/date/dateparser-inl.h | 2 +-
  18. src/date/dateparser.h | 4 +++-
  19. 2 files changed, 4 insertions(+), 2 deletions(-)
  20. diff --git a/src/date/dateparser-inl.h b/src/date/dateparser-inl.h
  21. index 623986d2b1..b45479dc51 100644
  22. --- a/src/date/dateparser-inl.h
  23. +++ b/src/date/dateparser-inl.h
  24. @@ -192,7 +192,7 @@ DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() {
  25. if (in_->Skip('+')) return DateToken::Symbol('+');
  26. if (in_->Skip('.')) return DateToken::Symbol('.');
  27. if (in_->Skip(')')) return DateToken::Symbol(')');
  28. - if (in_->IsAsciiAlphaOrAbove()) {
  29. + if (in_->IsAsciiAlphaOrAbove() && !in_->IsWhiteSpaceChar()) {
  30. DCHECK_EQ(KeywordTable::kPrefixLength, 3);
  31. uint32_t buffer[3] = {0, 0, 0};
  32. int length = in_->ReadWord(buffer, 3);
  33. diff --git a/src/date/dateparser.h b/src/date/dateparser.h
  34. index 1a0a0b15ab..59b2f3c9fd 100644
  35. --- a/src/date/dateparser.h
  36. +++ b/src/date/dateparser.h
  37. @@ -91,7 +91,8 @@ class DateParser : public AllStatic {
  38. // Return word length.
  39. int ReadWord(uint32_t* prefix, int prefix_size) {
  40. int len;
  41. - for (len = 0; IsAsciiAlphaOrAbove(); Next(), len++) {
  42. + for (len = 0; IsAsciiAlphaOrAbove() && !IsWhiteSpaceChar();
  43. + Next(), len++) {
  44. if (len < prefix_size) prefix[len] = AsciiAlphaToLower(ch_);
  45. }
  46. for (int i = len; i < prefix_size; i++) prefix[i] = 0;
  47. @@ -115,6 +116,7 @@ class DateParser : public AllStatic {
  48. bool IsEnd() const { return ch_ == 0; }
  49. bool IsAsciiDigit() const { return IsDecimalDigit(ch_); }
  50. bool IsAsciiAlphaOrAbove() const { return ch_ >= 'A'; }
  51. + bool IsWhiteSpaceChar() const { return IsWhiteSpace(ch_); }
  52. bool IsAsciiSign() const { return ch_ == '+' || ch_ == '-'; }
  53. // Return 1 for '+' and -1 for '-'.