Skip to content

Commit

Permalink
Fix character ranges in case insensitive regexp
Browse files Browse the repository at this point in the history
R=jgruber@chromium.org

Bug: chromium:971383
Change-Id: I39d26a63c0735f595a809959c06cb2ac1c141451
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1648098
Commit-Queue: Frank Tang <ftang@chromium.org>
Auto-Submit: Yang Guo <yangguo@chromium.org>
Reviewed-by: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62044}
  • Loading branch information
hashseed authored and Commit Bot committed Jun 7, 2019
1 parent ac30897 commit 9bcacf6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/d8/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include "src/utils/utils.h"
#include "src/wasm/wasm-engine.h"

#ifdef V8_INTL_SUPPORT
#include "unicode/locid.h"
#endif // V8_INTL_SUPPORT

#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h> // NOLINT
#else
Expand Down Expand Up @@ -2826,6 +2830,9 @@ bool Shell::SetOptions(int argc, char* argv[]) {
} else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) {
options.icu_data_file = argv[i] + 16;
argv[i] = nullptr;
} else if (strncmp(argv[i], "--icu-locale=", 13) == 0) {
options.icu_locale = argv[i] + 13;
argv[i] = nullptr;
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
} else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
options.natives_blob = argv[i] + 15;
Expand Down Expand Up @@ -3325,8 +3332,17 @@ void Shell::CleanupWorkers() {
int Shell::Main(int argc, char* argv[]) {
v8::base::EnsureConsoleOutput();
if (!SetOptions(argc, argv)) return 1;

v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);

#ifdef V8_INTL_SUPPORT
if (options.icu_locale != nullptr) {
icu::Locale locale(options.icu_locale);
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale::setDefault(locale, error_code);
}
#endif // V8_INTL_SUPPORT

v8::platform::InProcessStackDumping in_process_stack_dumping =
options.disable_in_process_stack_traces
? v8::platform::InProcessStackDumping::kDisabled
Expand Down
1 change: 1 addition & 0 deletions src/d8/d8.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class ShellOptions {
CodeCacheOptions code_cache_options = CodeCacheOptions::kNoProduceCache;
SourceGroup* isolate_sources = nullptr;
const char* icu_data_file = nullptr;
const char* icu_locale = nullptr;
const char* natives_blob = nullptr;
const char* snapshot_blob = nullptr;
bool trace_enabled = false;
Expand Down
6 changes: 4 additions & 2 deletions src/regexp/jsregexp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "src/zone/zone-list-inl.h"

#ifdef V8_INTL_SUPPORT
#include "unicode/locid.h"
#include "unicode/uniset.h"
#include "unicode/utypes.h"
#endif // V8_INTL_SUPPORT
Expand Down Expand Up @@ -5948,17 +5949,18 @@ void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone,
if (top > String::kMaxOneByteCharCode) top = String::kMaxOneByteCharCode;
}
already_added.add(bottom, top);
icu::Locale locale = icu::Locale::getRoot();
while (bottom <= top) {
icu::UnicodeString upper(bottom);
upper.toUpper();
upper.toUpper(locale);
icu::UnicodeSet expanded(bottom, bottom);
expanded.closeOver(USET_CASE_INSENSITIVE);
for (int32_t i = 0; i < expanded.getRangeCount(); i++) {
UChar32 start = expanded.getRangeStart(i);
UChar32 end = expanded.getRangeEnd(i);
while (start <= end) {
icu::UnicodeString upper2(start);
upper2.toUpper();
upper2.toUpper(locale);
// Only add if the upper case are the same.
if (upper[0] == upper2[0]) {
others.add(start);
Expand Down
7 changes: 7 additions & 0 deletions test/mjsunit/regress/regress-crbug-971383.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --icu-locale=tr

assertEquals(["HIJK"], "HIJK".match(/[a-z]+/gi));

0 comments on commit 9bcacf6

Please sign in to comment.