-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avm1: Fix string methods handling of negative args (fix #4437)
* Improve string.substr handling of negative args * Add tests for more substr() combinations
- Loading branch information
Showing
8 changed files
with
298 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/tests/swfs/avm1/string_methods_negative_args/Test.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Compile with: | ||
// mtasc -main -header 200:150:30 Test.as -swf test.swf | ||
class Test { | ||
static function main(current) { | ||
|
||
trace("// var str = hello world"); | ||
var str = "hello world"; | ||
trace("// str.substr(0, -1)"); | ||
trace(str.substr(0,-1)); | ||
trace("// str.substr(0, -4)"); | ||
trace(str.substr(0,-4)); | ||
trace("// str.substr(8, -4)"); | ||
trace(str.substr(8,-4)); | ||
trace("// str.substr(3, -3)"); | ||
trace(str.substr(3,-3)); | ||
trace("// str.substr(3, -4)"); | ||
trace(str.substr(3,-4)); | ||
trace("// str.substr(3, -5)"); | ||
trace(str.substr(3,-5)); | ||
trace("// str.substr(4, -4)"); | ||
trace(str.substr(4,-4)); | ||
trace("// str.substr(4, -5)"); | ||
trace(str.substr(4,-5)); | ||
trace("// str.substr(null, -1)"); | ||
trace(str.substr(null,-1)); | ||
trace("// str.substr(undefined, -1)"); | ||
trace(str.substr(undefined,-1)); | ||
|
||
var text = "abcd"; | ||
for (var i = -5; i < 5; i += 1) { | ||
trace("// text.substr(" + i + ")"); | ||
trace(text.substr(i)); | ||
for (var j = -5; j < 5; j += 1) { | ||
trace("// text.substr(" + i + "," + j + ")"); | ||
trace(text.substr(i, j)); | ||
} | ||
} | ||
} | ||
} |
241 changes: 241 additions & 0 deletions
241
tests/tests/swfs/avm1/string_methods_negative_args/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
// var str = hello world | ||
// str.substr(0, -1) | ||
hello worl | ||
// str.substr(0, -4) | ||
hello w | ||
// str.substr(8, -4) | ||
|
||
// str.substr(3, -3) | ||
|
||
// str.substr(3, -4) | ||
lo worl | ||
// str.substr(3, -5) | ||
lo wor | ||
// str.substr(4, -4) | ||
|
||
// str.substr(4, -5) | ||
o worl | ||
// str.substr(null, -1) | ||
hello worl | ||
// str.substr(undefined, -1) | ||
hello worl | ||
// text.substr(-5) | ||
abcd | ||
// text.substr(-5,-5) | ||
|
||
// text.substr(-5,-4) | ||
|
||
// text.substr(-5,-3) | ||
a | ||
// text.substr(-5,-2) | ||
ab | ||
// text.substr(-5,-1) | ||
abc | ||
// text.substr(-5,0) | ||
|
||
// text.substr(-5,1) | ||
a | ||
// text.substr(-5,2) | ||
ab | ||
// text.substr(-5,3) | ||
abc | ||
// text.substr(-5,4) | ||
abcd | ||
// text.substr(-4) | ||
abcd | ||
// text.substr(-4,-5) | ||
|
||
// text.substr(-4,-4) | ||
|
||
// text.substr(-4,-3) | ||
a | ||
// text.substr(-4,-2) | ||
ab | ||
// text.substr(-4,-1) | ||
abc | ||
// text.substr(-4,0) | ||
|
||
// text.substr(-4,1) | ||
a | ||
// text.substr(-4,2) | ||
ab | ||
// text.substr(-4,3) | ||
abc | ||
// text.substr(-4,4) | ||
abcd | ||
// text.substr(-3) | ||
bcd | ||
// text.substr(-3,-5) | ||
|
||
// text.substr(-3,-4) | ||
|
||
// text.substr(-3,-3) | ||
b | ||
// text.substr(-3,-2) | ||
bc | ||
// text.substr(-3,-1) | ||
|
||
// text.substr(-3,0) | ||
|
||
// text.substr(-3,1) | ||
b | ||
// text.substr(-3,2) | ||
bc | ||
// text.substr(-3,3) | ||
bcd | ||
// text.substr(-3,4) | ||
bcd | ||
// text.substr(-2) | ||
cd | ||
// text.substr(-2,-5) | ||
|
||
// text.substr(-2,-4) | ||
|
||
// text.substr(-2,-3) | ||
c | ||
// text.substr(-2,-2) | ||
|
||
// text.substr(-2,-1) | ||
|
||
// text.substr(-2,0) | ||
|
||
// text.substr(-2,1) | ||
c | ||
// text.substr(-2,2) | ||
cd | ||
// text.substr(-2,3) | ||
cd | ||
// text.substr(-2,4) | ||
cd | ||
// text.substr(-1) | ||
d | ||
// text.substr(-1,-5) | ||
|
||
// text.substr(-1,-4) | ||
|
||
// text.substr(-1,-3) | ||
|
||
// text.substr(-1,-2) | ||
|
||
// text.substr(-1,-1) | ||
|
||
// text.substr(-1,0) | ||
|
||
// text.substr(-1,1) | ||
d | ||
// text.substr(-1,2) | ||
d | ||
// text.substr(-1,3) | ||
d | ||
// text.substr(-1,4) | ||
d | ||
// text.substr(0) | ||
abcd | ||
// text.substr(0,-5) | ||
|
||
// text.substr(0,-4) | ||
|
||
// text.substr(0,-3) | ||
a | ||
// text.substr(0,-2) | ||
ab | ||
// text.substr(0,-1) | ||
abc | ||
// text.substr(0,0) | ||
|
||
// text.substr(0,1) | ||
a | ||
// text.substr(0,2) | ||
ab | ||
// text.substr(0,3) | ||
abc | ||
// text.substr(0,4) | ||
abcd | ||
// text.substr(1) | ||
bcd | ||
// text.substr(1,-5) | ||
|
||
// text.substr(1,-4) | ||
|
||
// text.substr(1,-3) | ||
b | ||
// text.substr(1,-2) | ||
bc | ||
// text.substr(1,-1) | ||
|
||
// text.substr(1,0) | ||
|
||
// text.substr(1,1) | ||
b | ||
// text.substr(1,2) | ||
bc | ||
// text.substr(1,3) | ||
bcd | ||
// text.substr(1,4) | ||
bcd | ||
// text.substr(2) | ||
cd | ||
// text.substr(2,-5) | ||
|
||
// text.substr(2,-4) | ||
|
||
// text.substr(2,-3) | ||
c | ||
// text.substr(2,-2) | ||
|
||
// text.substr(2,-1) | ||
|
||
// text.substr(2,0) | ||
|
||
// text.substr(2,1) | ||
c | ||
// text.substr(2,2) | ||
cd | ||
// text.substr(2,3) | ||
cd | ||
// text.substr(2,4) | ||
cd | ||
// text.substr(3) | ||
d | ||
// text.substr(3,-5) | ||
|
||
// text.substr(3,-4) | ||
|
||
// text.substr(3,-3) | ||
|
||
// text.substr(3,-2) | ||
|
||
// text.substr(3,-1) | ||
|
||
// text.substr(3,0) | ||
|
||
// text.substr(3,1) | ||
d | ||
// text.substr(3,2) | ||
d | ||
// text.substr(3,3) | ||
d | ||
// text.substr(3,4) | ||
d | ||
// text.substr(4) | ||
|
||
// text.substr(4,-5) | ||
|
||
// text.substr(4,-4) | ||
|
||
// text.substr(4,-3) | ||
|
||
// text.substr(4,-2) | ||
|
||
// text.substr(4,-1) | ||
|
||
// text.substr(4,0) | ||
|
||
// text.substr(4,1) | ||
|
||
// text.substr(4,2) | ||
|
||
// text.substr(4,3) | ||
|
||
// text.substr(4,4) | ||
|
Binary file not shown.
Oops, something went wrong.