Skip to content

Commit

Permalink
Fixes #191.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed Oct 20, 2023
1 parent d5acb44 commit 5cf9f40
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
40 changes: 25 additions & 15 deletions lib/new.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ NAN_METHOD(WrappedRE2::New)
bool hasIndices = false;

auto context = Nan::GetCurrentContext();
bool needFlags = true;

if (info.Length() > 1)
{
Expand Down Expand Up @@ -279,6 +280,7 @@ NAN_METHOD(WrappedRE2::New)
}
}
size = 0;
needFlags = false;
}

bool needConversion = true;
Expand All @@ -303,14 +305,18 @@ NAN_METHOD(WrappedRE2::New)

source = escapeRegExp(data, size);

v8::RegExp::Flags flags = re->GetFlags();
global = bool(flags & v8::RegExp::kGlobal);
ignoreCase = bool(flags & v8::RegExp::kIgnoreCase);
multiline = bool(flags & v8::RegExp::kMultiline);
dotAll = bool(flags & v8::RegExp::kDotAll);
unicode = bool(flags & v8::RegExp::kUnicode);
sticky = bool(flags & v8::RegExp::kSticky);
hasIndices = bool(flags & v8::RegExp::kHasIndices);
if (needFlags)
{
v8::RegExp::Flags flags = re->GetFlags();
global = bool(flags & v8::RegExp::kGlobal);
ignoreCase = bool(flags & v8::RegExp::kIgnoreCase);
multiline = bool(flags & v8::RegExp::kMultiline);
dotAll = bool(flags & v8::RegExp::kDotAll);
unicode = bool(flags & v8::RegExp::kUnicode);
sticky = bool(flags & v8::RegExp::kSticky);
hasIndices = bool(flags & v8::RegExp::kHasIndices);
needFlags = false;
}
}
else if (info[0]->IsObject() && !info[0]->IsString())
{
Expand All @@ -331,13 +337,17 @@ NAN_METHOD(WrappedRE2::New)

source = re2->source;

global = re2->global;
ignoreCase = re2->ignoreCase;
multiline = re2->multiline;
dotAll = re2->dotAll;
unicode = true;
sticky = re2->sticky;
hasIndices = re2->hasIndices;
if (needFlags)
{
global = re2->global;
ignoreCase = re2->ignoreCase;
multiline = re2->multiline;
dotAll = re2->dotAll;
unicode = true;
sticky = re2->sticky;
hasIndices = re2->hasIndices;
needFlags = false;
}
}
}
else if (info[0]->IsString())
Expand Down
39 changes: 39 additions & 0 deletions tests/test_general.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,45 @@ unit.add(module, [

re = new RE2("a", "smigyu");
eval(t.TEST("re.flags === 'gimsuy'"));
},
function test_flags_2nd(t) {
"use strict";

var re = new RE2(/a/, "u");
eval(t.TEST("re.flags === 'u'"));

re = new RE2(/a/gm, "iu");
eval(t.TEST("re.flags === 'iu'"));

re = new RE2(/a/ig, "mu");
eval(t.TEST("re.flags === 'mu'"));

re = new RE2(/a/g, "gu");
eval(t.TEST("re.flags === 'gu'"));

re = new RE2(/a/m, "yu");
eval(t.TEST("re.flags === 'uy'"));

re = new RE2(/a/, "yiu");
eval(t.TEST("re.flags === 'iuy'"));

re = new RE2(/a/gim, "yigu");
eval(t.TEST("re.flags === 'giuy'"));

re = new RE2(/a/gm, "miu");
eval(t.TEST("re.flags === 'imu'"));

re = new RE2(/a/i, "ygu");
eval(t.TEST("re.flags === 'guy'"));

re = new RE2(/a/g, "myu");
eval(t.TEST("re.flags === 'muy'"));

re = new RE2(/a/, "migyu");
eval(t.TEST("re.flags === 'gimuy'"));

re = new RE2(/a/s, "smigyu");
eval(t.TEST("re.flags === 'gimsuy'"));
}
]);

Expand Down

0 comments on commit 5cf9f40

Please sign in to comment.