Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RegExp named groups identifiers coverage #2588

Merged
merged 7 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016 the Apple Inc. All rights reserved.
// Copyright (C) 2016 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.prototype.tostring
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016 the Apple Inc. All rights reserved.
// Copyright (C) 2016 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.prototype.tostring
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2020 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Michael Saboff
description: Invalid exotic named group names in non-Unicode RegExps
esid: prod-GroupSpecifier
features: [regexp-named-groups]
---*/

/*
Valid ID_Continue Unicode characters (Can't be first identifier character.)

𝟚 \u{1d7da} \ud835 \udfda

Invalid ID_Start / ID_Continue

(fox face emoji) 🦊 \u{1f98a} \ud83e \udd8a
(dog emoji) 🐕 \u{1f415} \ud83d \udc15
*/

assert.throws(SyntaxError, function() {
return new RegExp("(?<🦊>fox)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1f98a}>fox)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud83e\udd8a>fox)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<🐕>dog)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1f415}>dog)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud83d \udc15>dog)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<𝟚the>the)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1d7da}the>the)");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud835\udfdathe>the)");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (C) 2020 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Michael Saboff
description: Exotic named group names in non-Unicode RegExps
esid: prod-GroupSpecifier
features: [regexp-named-groups]
---*/

/*
Valid ID_Start / ID_Continue Unicode characters

𝑓 \u{1d453} \ud835 \udc53
𝑜 \u{1d45c} \ud835 \udc5c
𝑥 \u{id465} \ud835 \udc65

𝓓 \u{1d4d3} \ud835 \udcd3
𝓸 \u{1d4f8} \ud835 \udcf8
𝓰 \u{1d4f0} \ud835 \udcf0

𝓑 \u{1d4d1} \ud835 \udcd1
𝓻 \u{1d4fb} \ud835 \udcfb
𝓸 \u{1d4f8} \ud835 \udcf8
𝔀 \u{1d500} \ud835 \udd00
𝓷 \u{1d4f7} \ud835 \udcf7

𝖰 \u{1d5b0} \ud835 \uddb0
𝖡 \u{1d5a1} \ud835 \udda1
𝖥 \u{1d5a5} \ud835 \udda5

(fox) 狸 \u{72f8} \u72f8
(dog) 狗 \u{72d7} \u72d7

Valid ID_Continue Unicode characters (Can't be first identifier character.)

𝟚 \u{1d7da} \ud835 \udfda
*/

var string = "The quick brown fox jumped over the lazy dog's back";
var string2 = "It is a dog eat dog world.";

let match = null;

assert.sameValue(string.match(/(?<animal>fox|dog)/).groups.animal, "fox");

match = string.match(/(?<𝑓𝑜𝑥>fox).*(?<𝓓𝓸𝓰>dog)/);
assert.sameValue(match.groups.𝑓𝑜𝑥, "fox");
assert.sameValue(match.groups.𝓓𝓸𝓰, "dog");
assert.sameValue(match[1], "fox");
assert.sameValue(match[2], "dog");

match = string.match(/(?<狸>fox).*(?<狗>dog)/);
assert.sameValue(match.groups.狸, "fox");
assert.sameValue(match.groups.狗, "dog");
assert.sameValue(match[1], "fox");
assert.sameValue(match[2], "dog");

assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");
assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");
assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");

assert.sameValue(string.match(/(?<𝖰𝖡𝖥>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰𝖡\u{1d5a5}>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰\u{1d5a1}𝖥>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}𝖡𝖥>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}𝖡\u{1d5a5}>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}𝖥>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/).groups.𝖰𝖡𝖥, "quick brown fox");

assert.sameValue(string.match(/(?<the𝟚>the)/).groups.the𝟚, "the");
assert.sameValue(string.match(/(?<the\u{1d7da}>the)/).groups.the𝟚, "the");
assert.sameValue(string.match(/(?<the\ud835\udfda>the)/).groups.the𝟚, "the");

match = string2.match(/(?<dog>dog)(.*?)(\k<dog>)/);
assert.sameValue(match.groups.dog, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");

match = string2.match(/(?<𝓓𝓸𝓰>dog)(.*?)(\k<𝓓𝓸𝓰>)/);
assert.sameValue(match.groups.𝓓𝓸𝓰, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");

match = string2.match(/(?<狗>dog)(.*?)(\k<狗>)/);
assert.sameValue(match.groups.狗, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2020 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Michael Saboff
description: Invalid exotic named group names in Unicode RegExps
esid: prod-GroupSpecifier
features: [regexp-named-groups]
---*/

/*
Valid ID_Continue Unicode characters (Can't be first identifier character.)

𝟚 \u{1d7da} \ud835 \udfda

Invalid ID_Start / ID_Continue

(fox face emoji) 🦊 \u{1f98a} \ud83e \udd8a
(dog emoji) 🐕 \u{1f415} \ud83d \udc15
*/

assert.throws(SyntaxError, function() {
return new RegExp("(?<🦊>fox)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1f98a}>fox)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud83e\udd8a>fox)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<🐕>dog)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1f415}>dog)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud83d \udc15>dog)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<𝟚the>the)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\u{1d7da}the>the)", "u");
});

assert.throws(SyntaxError, function() {
return new RegExp("(?<\ud835\udfdathe>the)", "u");
});
100 changes: 100 additions & 0 deletions test/built-ins/RegExp/named-groups/unicode-property-names-valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (C) 2020 Apple Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Michael Saboff
description: Exotic named group names in Unicode RegExps
esid: prod-GroupSpecifier
features: [regexp-named-groups]
---*/

/*
Valid ID_Start / ID_Continue Unicode characters

𝑓 \u{1d453} \ud835 \udc53
𝑜 \u{1d45c} \ud835 \udc5c
𝑥 \u{id465} \ud835 \udc65

𝓓 \u{1d4d3} \ud835 \udcd3
𝓸 \u{1d4f8} \ud835 \udcf8
𝓰 \u{1d4f0} \ud835 \udcf0

𝓑 \u{1d4d1} \ud835 \udcd1
𝓻 \u{1d4fb} \ud835 \udcfb
𝓸 \u{1d4f8} \ud835 \udcf8
𝔀 \u{1d500} \ud835 \udd00
𝓷 \u{1d4f7} \ud835 \udcf7

𝖰 \u{1d5b0} \ud835 \uddb0
𝖡 \u{1d5a1} \ud835 \udda1
𝖥 \u{1d5a5} \ud835 \udda5

(fox) 狸 \u{72f8} \u72f8
(dog) 狗 \u{72d7} \u72d7

Valid ID_Continue Unicode characters (Can't be first identifier character.)

𝟚 \u{1d7da} \ud835 \udfda

Invalid ID_Start / ID_Continue

(fox face emoji) 🦊 \u{1f98a} \ud83e \udd8a
(dog emoji) 🐕 \u{1f415} \ud83d \udc15
*/

var string = "The quick brown fox jumped over the lazy dog's back";
var string2 = "It is a dog eat dog world.";

let match = null;

assert.sameValue(string.match(/(?<animal>fox|dog)/u).groups.animal, "fox");
assert.sameValue(string.match(/(?<the2>the)/u).groups.the2, "the");

match = string.match(/(?<𝑓𝑜𝑥>fox).*(?<𝓓𝓸𝓰>dog)/u);
assert.sameValue(match.groups.𝑓𝑜𝑥, "fox");
assert.sameValue(match.groups.𝓓𝓸𝓰, "dog");
assert.sameValue(match[1], "fox");
assert.sameValue(match[2], "dog");

match = string.match(/(?<狸>fox).*(?<狗>dog)/u);
assert.sameValue(match.groups.狸, "fox");
assert.sameValue(match.groups.狗, "dog");
assert.sameValue(match[1], "fox");
assert.sameValue(match[2], "dog");

assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");
assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");
assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown");
assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown");

assert.sameValue(string.match(/(?<𝖰𝖡𝖥>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰𝖡\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰\u{1d5a1}𝖥>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<𝖰\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}𝖡𝖥>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}𝖡\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}𝖥>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");
assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖡𝖥, "quick brown fox");

assert.sameValue(string.match(/(?<the𝟚>the)/u).groups.the𝟚, "the");
assert.sameValue(string.match(/(?<the\u{1d7da}>the)/u).groups.the𝟚, "the");
assert.sameValue(string.match(/(?<the\ud835\udfda>the)/u).groups.the𝟚, "the");

match = string2.match(/(?<dog>dog)(.*?)(\k<dog>)/u);
assert.sameValue(match.groups.dog, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");

match = string2.match(/(?<𝓓𝓸𝓰>dog)(.*?)(\k<𝓓𝓸𝓰>)/u);
assert.sameValue(match.groups.𝓓𝓸𝓰, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");

match = string2.match(/(?<狗>dog)(.*?)(\k<狗>)/u);
assert.sameValue(match.groups.狗, "dog");
assert.sameValue(match[1], "dog");
assert.sameValue(match[2], " eat ");
assert.sameValue(match[3], "dog");
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ features: [regexp-named-groups]

$DONOTEVALUATE();

/(?<$𐒤>a)/;
/(?<$>a)/;
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ features: [regexp-named-groups]

$DONOTEVALUATE();

/(?<a\uD801\uDCA4>.)/;
/(?<a\uD83D\uDF12>.)/;
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ features: [regexp-named-groups]

$DONOTEVALUATE();

/(?<a\u{104A4}>.)/;
/(?<a\u{1F08B}>.)/;

This file was deleted.

This file was deleted.