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

Add property "original" to RegExp since property "source" is not clearly specified #577

Closed
matthewadams opened this Issue May 19, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@matthewadams

matthewadams commented May 19, 2016

The output of RegExp.source changed on us.

When node@0.12.14 with v8@3.28.71.19 upgraded to node@4.0.0 with v8@4.5.103.30, the output of RegExp.source changed. The data below from my tests show it clearly, which uses new RegExp('/test').source.

node        v8             new RegExp('/test').source
----------- -------------- -----------------------------------
v0.12.14    3.28.71.19     /test
v4.0.0      4.5.103.30     \/test

Beginning with node@4.0.0/v8@4.5.103.30, RegExp.source now escapes forward slashes, which broke one of our scripts. With this change, there is no way to get the original string s given in new RegExp(s). This strikes me as a deficiency, for which I have two suggestions.

(1) ECMAScript to specify a new property original that would return the original string given to new RegExp(). That way, source can keep returning whatever it wants to, which, currently, is an arbitrarily formatted string, provided that it behaves the same way as the original string when given to new RegExp(), and original would return the string originally given to new RegExp().

(2) source could revert to the older v8 behavior, be specified to return the original string as given to new RegExp(), and a new canonical property could be added that clearly specifies how a RegExp should be formatted in a standard way.

I imagine it might be too late for (2), but, in either case, it would be nice if ECMAScript at least standardized source to return predictable values across implementations, as discussed previously.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 19, 2016

Contributor

(1) ECMAScript to specify a new property original that would return the original string given to new RegExp(). That way, source can keep returning whatever it wants to, which, currently, is an arbitrarily formatted string, provided that it behaves the same way as the original string when given to new RegExp(), and original would return the string originally given to new RegExp().

See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests

(2) source could revert to the older v8 behavior, be specified to return the original string as given o new RegExp(), and a new canonical property could be added that clearly specifies how a RegExp should be formatted in a standard way.

The change of behaviour of RegExp('/test').source in v8 was needed in order to conform to the spec since ES6 ES5. In previous versions, it was less tightly specified. See RegExp.prototype.source last step and EscapeRegExpPattern step 2.

Contributor

claudepache commented May 19, 2016

(1) ECMAScript to specify a new property original that would return the original string given to new RegExp(). That way, source can keep returning whatever it wants to, which, currently, is an arbitrarily formatted string, provided that it behaves the same way as the original string when given to new RegExp(), and original would return the string originally given to new RegExp().

See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests

(2) source could revert to the older v8 behavior, be specified to return the original string as given o new RegExp(), and a new canonical property could be added that clearly specifies how a RegExp should be formatted in a standard way.

The change of behaviour of RegExp('/test').source in v8 was needed in order to conform to the spec since ES6 ES5. In previous versions, it was less tightly specified. See RegExp.prototype.source last step and EscapeRegExpPattern step 2.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 19, 2016

Contributor

in order to conform to the spec since ES6

In fact, that behaviour (escaping /) was already required in ES5.1.

Contributor

claudepache commented May 19, 2016

in order to conform to the spec since ES6

In fact, that behaviour (escaping /) was already required in ES5.1.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Sep 12, 2016

Member

Closing this. If there's still an issue here please see CONTRIBUTING.md.

Member

bterlson commented Sep 12, 2016

Closing this. If there's still an issue here please see CONTRIBUTING.md.

@bterlson bterlson closed this Sep 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment