Closed dimonomid closed 8 years ago
sorry, I didn't forget, I'll review this tomorrow.
Sergey asked to keep PRs containing just 1 commit, so, here we go: https://github.com/cesanta/v7/pull/512 . Closing this one.
We don't mind (actually encourage) squashing and force pushing one's personal feature branch. So next time feel free to do that instead of creating a new PR.
On Mon, 19 Oct 2015, 23:22 Dmitry Frank notifications@github.com wrote:
Sergey asked to keep PRs containing just 1 commit, so, here we go: #512 https://github.com/cesanta/v7/pull/512 . Closing this one.
— Reply to this email directly or view it on GitHub https://github.com/cesanta/v7/pull/510#issuecomment-149351356.
Oh, ok, got it.
As the title suggests, if the separator given to
String.prototype.split()
is anything but RegExp, it is interpreted as String, and source string gets splitted by the plain string instead of RegExp. It works if v7 is built without RegExp support.In addition, a couple of issues fixed, so that behavior of
String.prototype.split()
is now identical to that of browsers (Firefox, Chrome, Opera)1:
Accordingly to spec, if pattern does not match an empty string, then the empty substring at the end of the source string should be included in the resulting array:
'123'.split(RegExp('.'))
should evaluate to[ '', '', '', '' ]
, but previously it evaluated to[ '', '', '' ]
.'123'.split(/2*/)
should evaluate to['1', '3']
, but previously it evaluated to['1', '', '3']
2:
Accordingly to spec,
''.split(/.*/)
should evaluate to[]
, not[ '' ]
, since given pattern matches an empty string.Details in spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.14
3:
Non-ASCII strings were not handled correctly: for example,
'абв'.split(RegExp(''))
should evaluate to["а","б","в"]
, but previously it evaluated to["�","�","�","�","�","�"]
4:
When the pattern contains capture groups, resulting array contained extra items:
'123'.split(/(x)*/)
should evaluate to["1",undefined,"2",undefined,"3"]
, but previously it evaluated to["1",undefined,"2",undefined,"3",undefined]
(notice an extra trailingundefined
)5:
Limit wasn't handled correctly. For example,
'123'.split(/(x)*/, 2)
should evaluate to["1",undefined]
, but it evaluated to["1",undefined,"2",undefined]