Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_nashorn
提交
5029f458
D
dragonwell8_nashorn
项目概览
openanolis
/
dragonwell8_nashorn
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_nashorn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5029f458
编写于
4月 10, 2013
作者:
H
hannesw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8011714: Regexp decimal escape handling still not correct
Reviewed-by: lagergren, attila
上级
24978733
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
174 addition
and
49 deletion
+174
-49
src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java
src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java
+79
-49
test/script/basic/JDK-8011714.js
test/script/basic/JDK-8011714.js
+68
-0
test/script/basic/JDK-8011714.js.EXPECTED
test/script/basic/JDK-8011714.js.EXPECTED
+27
-0
未找到文件。
src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java
浏览文件 @
5029f458
...
...
@@ -108,15 +108,11 @@ final class RegExpScanner extends Scanner {
final
int
pos
=
iterator
.
next
();
final
int
num
=
iterator
.
next
();
if
(
num
>
caps
.
size
())
{
// Non-existing reference should never match, if smaller than 8 convert to octal escape
// to be compatible with other engines.
if
(
num
<
8
)
{
String
escape
=
"\\x0"
+
num
;
sb
.
insert
(
pos
,
escape
);
}
else
{
neverMatches
=
true
;
break
;
}
// Non-existing backreference. If the number begins with a valid octal convert it to
// Unicode escape and append the rest to a literal character sequence.
final
StringBuilder
buffer
=
new
StringBuilder
();
octalOrLiteral
(
Integer
.
toString
(
num
),
buffer
);
sb
.
insert
(
pos
,
buffer
);
}
}
...
...
@@ -632,7 +628,7 @@ final class RegExpScanner extends Scanner {
// form "\\ca".match([string with ascii 1 at char0]). Translating
// them to unicode does it though.
sb
.
setLength
(
sb
.
length
()
-
1
);
unicode
(
c
-
'A'
+
1
);
unicode
(
c
-
'A'
+
1
,
sb
);
skip
(
1
);
return
true
;
}
...
...
@@ -673,7 +669,7 @@ final class RegExpScanner extends Scanner {
final
int
startIn
=
position
;
final
int
startOut
=
sb
.
length
();
if
(
ch0
==
'0'
&&
!
is
Decim
alDigit
(
ch1
))
{
if
(
ch0
==
'0'
&&
!
is
Oct
alDigit
(
ch1
))
{
skip
(
1
);
// DecimalEscape :: 0. If i is zero, return the EscapeValue consisting of a <NUL> character (Unicodevalue0000);
sb
.
append
(
"\u0000"
);
...
...
@@ -681,50 +677,56 @@ final class RegExpScanner extends Scanner {
}
if
(
isDecimalDigit
(
ch0
))
{
final
int
num
=
ch0
-
'0'
;
// Single digit escape, treat as backreference.
if
(!
isDecimalDigit
(
ch1
))
{
if
(
num
<=
caps
.
size
()
&&
caps
.
get
(
num
-
1
).
getNegativeLookaheadLevel
()
>
0
)
{
if
(
ch0
==
'0'
)
{
// We know this is an octal escape.
if
(
inCharClass
)
{
// Convert octal escape to unicode escape if inside character class.
int
octalValue
=
0
;
while
(
isOctalDigit
(
ch0
))
{
octalValue
=
octalValue
*
8
+
ch0
-
'0'
;
skip
(
1
);
}
unicode
(
octalValue
,
sb
);
}
else
{
// Copy decimal escape as-is
decimalDigits
();
}
}
else
{
// This should be a backreference, but could also be an octal escape or even a literal string.
int
decimalValue
=
0
;
while
(
isDecimalDigit
(
ch0
))
{
decimalValue
=
decimalValue
*
10
+
ch0
-
'0'
;
skip
(
1
);
}
if
(
inCharClass
)
{
// No backreferences in character classes. Encode as unicode escape or literal char sequence
sb
.
setLength
(
sb
.
length
()
-
1
);
octalOrLiteral
(
Integer
.
toString
(
decimalValue
),
sb
);
}
else
if
(
decimalValue
<=
caps
.
size
()
&&
caps
.
get
(
decimalValue
-
1
).
getNegativeLookaheadLevel
()
>
0
)
{
// Captures that live inside a negative lookahead are dead after the
// lookahead and will be undefined if referenced from outside.
if
(
caps
.
get
(
num
-
1
).
getNegativeLookaheadLevel
()
>
negativeLookaheadLevel
)
{
if
(
caps
.
get
(
decimalValue
-
1
).
getNegativeLookaheadLevel
()
>
negativeLookaheadLevel
)
{
sb
.
setLength
(
sb
.
length
()
-
1
);
}
else
{
sb
.
append
(
ch0
);
sb
.
append
(
decimalValue
);
}
skip
(
1
);
return
true
;
}
else
if
(
num
>
caps
.
size
())
{
// Forward reference to a capture group. Forward references are always undefined so we
// can omit it from the output buffer. Additionally, if the capture group does not exist
// the whole regexp becomes invalid, so register the reference for later processing.
}
else
if
(
decimalValue
>
caps
.
size
())
{
// Forward reference to a capture group. Forward references are always undefined so we can omit
// it from the output buffer. However, if the target capture does not exist, we need to rewrite
// the reference as hex escape or literal string, so register the reference for later processing.
sb
.
setLength
(
sb
.
length
()
-
1
);
forwardReferences
.
add
(
num
);
forwardReferences
.
add
(
decimalValue
);
forwardReferences
.
add
(
sb
.
length
());
skip
(
1
);
return
true
;
}
}
if
(
inCharClass
)
{
// Convert octal escape to unicode escape if inside character class.
StringBuilder
digit
=
new
StringBuilder
(
4
);
while
(
isDecimalDigit
(
ch0
))
{
digit
.
append
(
ch0
);
skip
(
1
);
}
int
value
=
Integer
.
parseInt
(
digit
.
toString
(),
8
);
//throws exception that leads to SyntaxError if not octal
if
(
value
>
0xff
)
{
throw
new
NumberFormatException
(
digit
.
toString
());
}
else
{
// Append as backreference
sb
.
append
(
decimalValue
);
}
unicode
(
value
);
}
else
{
// Copy decimal escape as-is
decimalDigits
();
}
return
true
;
}
...
...
@@ -965,13 +967,41 @@ final class RegExpScanner extends Scanner {
return
true
;
}
private
void
unicode
(
final
int
value
)
{
private
void
unicode
(
final
int
value
,
final
StringBuilder
buffer
)
{
final
String
hex
=
Integer
.
toHexString
(
value
);
sb
.
append
(
'u'
);
buffer
.
append
(
'u'
);
for
(
int
i
=
0
;
i
<
4
-
hex
.
length
();
i
++)
{
sb
.
append
(
'0'
);
buffer
.
append
(
'0'
);
}
buffer
.
append
(
hex
);
}
// Convert what would have been a backreference into a unicode escape, or a number literal, or both.
private
void
octalOrLiteral
(
final
String
numberLiteral
,
final
StringBuilder
buffer
)
{
final
int
length
=
numberLiteral
.
length
();
int
octalValue
=
0
;
int
pos
=
0
;
// Maximum value for octal escape is 0377 (255) so we stop the loop at 32
while
(
pos
<
length
&&
octalValue
<
0x20
)
{
final
char
ch
=
numberLiteral
.
charAt
(
pos
);
if
(
isOctalDigit
(
ch
))
{
octalValue
=
octalValue
*
8
+
ch
-
'0'
;
}
else
{
break
;
}
pos
++;
}
if
(
octalValue
>
0
)
{
buffer
.
append
(
'\\'
);
unicode
(
octalValue
,
buffer
);
buffer
.
append
(
numberLiteral
.
substring
(
pos
));
}
else
{
buffer
.
append
(
numberLiteral
);
}
sb
.
append
(
hex
);
}
private
static
boolean
isOctalDigit
(
final
char
ch
)
{
return
ch
>=
'0'
&&
ch
<=
'7'
;
}
private
static
boolean
isDecimalDigit
(
final
char
ch
)
{
...
...
test/script/basic/JDK-8011714.js
0 → 100644
浏览文件 @
5029f458
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8011714: Regexp decimal escape handling still not correct
*
* @test
* @run
*/
// \0 should be interpreted as <NUL> character here
print
(
/
\0
8/
.
test
(
"
\
x008
"
));
print
(
/
[\0
8
]
/
.
test
(
"
8
"
));
print
(
/
[\0
8
]
/
.
test
(
"
\
x00
"
));
// Can't be converted to octal thus encoded as literal char sequence
print
(
/
\8
/
.
exec
(
"
\\
8
"
));
print
(
/
[\8]
/
.
exec
(
"
\\
"
));
print
(
/
[\8]
/
.
exec
(
"
8
"
));
// 0471 is too high for an octal escape so it is \047 outside a character class
// and \\471 inside a character class
print
(
/
\4
71/
.
exec
(
"
\
x271
"
));
print
(
/
[\4
71
]
/
.
exec
(
"
1
"
));
print
(
/
[\4
71
]
/
.
exec
(
"
\
x27
"
));
// 0366 is a valid octal escape (246)
print
(
/
\3
66/
.
test
(
"
\
xf6
"
));
print
(
/
[\3
66
]
/
.
test
(
"
\
xf6
"
));
print
(
/
[\3
66
]
/
.
test
(
"
\
xf6
"
));
// more tests for conversion of invalid backreferences to octal escapes or literals
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
/
.
exec
(
"
abcdd
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
x/
.
exec
(
"
abcddx
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
7/
.
exec
(
"
abcdd7
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
7/
.
exec
(
"
abcd
\
x27
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
7xyz/
.
exec
(
"
abcd
\
x27xyz
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\4
7
]
/
.
exec
(
"
abcd
\
x27
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\4
7
]
xyz/
.
exec
(
"
abcd
\
x27xyz
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
8/
.
exec
(
"
abcd
\
x048
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\4
8xyz/
.
exec
(
"
abcd
\
x048xyz
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\4
8
]
/
.
exec
(
"
abcd
\
x04
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\4
8
]
xyz/
.
exec
(
"
abcd
\
x04xyz
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\8
4/
.
exec
(
"
abcd84
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)\8
4xyz/
.
exec
(
"
abcd84xyz
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\8
4
]
/
.
exec
(
"
abcd8
"
));
print
(
/
(
a
)(
b
)(
c
)(
d
)[\8
4
]
xyz/
.
exec
(
"
abcd8xyz
"
));
test/script/basic/JDK-8011714.js.EXPECTED
0 → 100644
浏览文件 @
5029f458
true
true
true
8
null
8
'1
1
'
true
true
true
abcdd,a,b,c,d
abcddx,a,b,c,d
null
abcd',a,b,c,d
abcd'xyz,a,b,c,d
abcd',a,b,c,d
abcd'xyz,a,b,c,d
abcd8,a,b,c,d
abcd8xyz,a,b,c,d
abcd,a,b,c,d
abcdxyz,a,b,c,d
abcd84,a,b,c,d
abcd84xyz,a,b,c,d
abcd8,a,b,c,d
abcd8xyz,a,b,c,d
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录