Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
eba4b1fd
Unverified
Commit
eba4b1fd
authored
Mar 05, 2017
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check modifiable for String `bang' methods
parent
d0506945
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
mrbgems/mruby-string-ext/mrblib/string.rb
mrbgems/mruby-string-ext/mrblib/string.rb
+4
-0
mrblib/string.rb
mrblib/string.rb
+2
-0
No files found.
mrbgems/mruby-string-ext/mrblib/string.rb
View file @
eba4b1fd
...
@@ -95,6 +95,7 @@ class String
...
@@ -95,6 +95,7 @@ class String
# "hello".lstrip! #=> nil
# "hello".lstrip! #=> nil
#
#
def
lstrip!
def
lstrip!
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
s
=
self
.
lstrip
s
=
self
.
lstrip
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
end
end
...
@@ -111,6 +112,7 @@ class String
...
@@ -111,6 +112,7 @@ class String
# "hello".rstrip! #=> nil
# "hello".rstrip! #=> nil
#
#
def
rstrip!
def
rstrip!
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
s
=
self
.
rstrip
s
=
self
.
rstrip
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
end
end
...
@@ -123,6 +125,7 @@ class String
...
@@ -123,6 +125,7 @@ class String
# <code>nil</code> if <i>str</i> was not altered.
# <code>nil</code> if <i>str</i> was not altered.
#
#
def
strip!
def
strip!
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
s
=
self
.
strip
s
=
self
.
strip
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
(
s
==
self
)
?
nil
:
self
.
replace
(
s
)
end
end
...
@@ -183,6 +186,7 @@ class String
...
@@ -183,6 +186,7 @@ class String
# string #=> "thsa sting"
# string #=> "thsa sting"
#
#
def
slice!
(
arg1
,
arg2
=
nil
)
def
slice!
(
arg1
,
arg2
=
nil
)
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
raise
"wrong number of arguments (for 1..2)"
if
arg1
.
nil?
&&
arg2
.
nil?
raise
"wrong number of arguments (for 1..2)"
if
arg1
.
nil?
&&
arg2
.
nil?
if
!
arg1
.
nil?
&&
!
arg2
.
nil?
if
!
arg1
.
nil?
&&
!
arg2
.
nil?
...
...
mrblib/string.rb
View file @
eba4b1fd
...
@@ -78,6 +78,7 @@ class String
...
@@ -78,6 +78,7 @@ class String
#
#
# ISO 15.2.10.5.19
# ISO 15.2.10.5.19
def
gsub!
(
*
args
,
&
block
)
def
gsub!
(
*
args
,
&
block
)
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
str
=
self
.
gsub
(
*
args
,
&
block
)
str
=
self
.
gsub
(
*
args
,
&
block
)
return
nil
if
str
==
self
return
nil
if
str
==
self
self
.
replace
(
str
)
self
.
replace
(
str
)
...
@@ -123,6 +124,7 @@ class String
...
@@ -123,6 +124,7 @@ class String
#
#
# ISO 15.2.10.5.37
# ISO 15.2.10.5.37
def
sub!
(
*
args
,
&
block
)
def
sub!
(
*
args
,
&
block
)
raise
RuntimeError
,
"can't modify frozen String"
if
frozen?
str
=
self
.
sub
(
*
args
,
&
block
)
str
=
self
.
sub
(
*
args
,
&
block
)
return
nil
if
str
==
self
return
nil
if
str
==
self
self
.
replace
(
str
)
self
.
replace
(
str
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment