Skip to content

Commit 58ef7c2

Browse files
committed
* regex.c (re_compile_pattern): fix previous change.
* instruby.rb, ext/extmk.rb, ext/tk/lib/tk.rb, lib/benchmark.rb, lib/cgi.rb, lib/debug.rb, lib/getoptlong.rb, lib/jcode.rb, lib/optparse.rb, lib/time.rb, lib/date/format.rb, lib/irb/ruby-lex.rb: escape `[', `]', `-' in chracter class in regexp to avoid warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 108cf94 commit 58ef7c2

File tree

14 files changed

+56
-46
lines changed

14 files changed

+56
-46
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Fri Mar 21 23:40:41 2003 Tanaka Akira <akr@m17n.org>
2+
3+
* regex.c (re_compile_pattern): fix previous change.
4+
5+
* instruby.rb, ext/extmk.rb, ext/tk/lib/tk.rb, lib/benchmark.rb,
6+
lib/cgi.rb, lib/debug.rb, lib/getoptlong.rb, lib/jcode.rb,
7+
lib/optparse.rb, lib/time.rb, lib/date/format.rb,
8+
lib/irb/ruby-lex.rb: escape `[', `]', `-' in chracter class in
9+
regexp to avoid warning.
10+
111
Fri Mar 21 23:23:45 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
212

313
* regex.c (re_compile_pattern): give warning for unescaped square

ext/extmk.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def parse_args()
127127

128128
$mflags = Shellwords.shellwords(mflags)
129129
if arg = $mflags.first
130-
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
130+
arg.insert(0, '-') if /\A[^\-][^=]*\Z/ =~ arg
131131
end
132132

133133
$make, *rest = Shellwords.shellwords($make)

ext/tk/lib/tk.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def appsend(interp, async, *args)
605605
end
606606

607607
def rb_appsend(interp, async, *args)
608-
args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
608+
args = args.collect!{|c| _get_eval_string(c).gsub(/[\]\[$"]/, '\\\\\&')}
609609
args.push(').to_s"')
610610
appsend(interp, async, 'ruby "(', *args)
611611
end
@@ -620,7 +620,7 @@ def appsend_displayof(interp, win, async, *args)
620620
end
621621

622622
def rb_appsend_displayof(interp, win, async, *args)
623-
args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
623+
args = args.collect!{|c| _get_eval_string(c).gsub(/[\]\[$"]/, '\\\\\&')}
624624
args.push(').to_s"')
625625
appsend_displayof(interp, win, async, 'ruby "(', *args)
626626
end
@@ -1179,14 +1179,14 @@ def initialize(val="")
11791179
elsif val.kind_of?(Array)
11801180
a = []
11811181
val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))}
1182-
s = '"' + a.join(" ").gsub(/[][$"]/, '\\\\\&') + '"'
1182+
s = '"' + a.join(" ").gsub(/[\]\[$"]/, '\\\\\&') + '"'
11831183
INTERP._eval(format('global %s; array set %s %s', @id, @id, s))
11841184
elsif val.kind_of?(Hash)
11851185
s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\
1186-
.gsub(/[][$"]/, '\\\\\&') + '"'
1186+
.gsub(/[\]\[$"]/, '\\\\\&') + '"'
11871187
INTERP._eval(format('global %s; array set %s %s', @id, @id, s))
11881188
else
1189-
s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"'
1189+
s = '"' + _get_eval_string(val).gsub(/[\]\[$"]/, '\\\\\&') + '"'
11901190
INTERP._eval(format('global %s; set %s %s', @id, @id, s))
11911191
end
11921192
end
@@ -1214,7 +1214,7 @@ def value
12141214

12151215
def value=(val)
12161216
begin
1217-
s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"'
1217+
s = '"' + _get_eval_string(val).gsub(/[\]\[$"]/, '\\\\\&') + '"'
12181218
INTERP._eval(format('global %s; set %s %s', @id, @id, s))
12191219
rescue
12201220
if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1"
@@ -1226,12 +1226,12 @@ def value=(val)
12261226
elsif val.kind_of?(Array)
12271227
a = []
12281228
val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))}
1229-
s = '"' + a.join(" ").gsub(/[][$"]/, '\\\\\&') + '"'
1229+
s = '"' + a.join(" ").gsub(/[\]\[$"]/, '\\\\\&') + '"'
12301230
INTERP._eval(format('global %s; unset %s; array set %s %s',
12311231
@id, @id, @id, s))
12321232
elsif val.kind_of?(Hash)
12331233
s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\
1234-
.gsub(/[][$"]/, '\\\\\&') + '"'
1234+
.gsub(/[\]\[$"]/, '\\\\\&') + '"'
12351235
INTERP._eval(format('global %s; unset %s; array set %s %s',
12361236
@id, @id, @id, s))
12371237
else
@@ -1438,7 +1438,7 @@ class TkVarAccess<TkVariable
14381438
def initialize(varname, val=nil)
14391439
@id = varname
14401440
if val
1441-
s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"' #"
1441+
s = '"' + _get_eval_string(val).gsub(/[\]\[$"]/, '\\\\\&') + '"' #"
14421442
INTERP._eval(format('global %s; set %s %s', @id, @id, s))
14431443
end
14441444
end

instruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def parse_args()
2525

2626
$mflags = Shellwords.shellwords(mflags)
2727
if arg = $mflags.first
28-
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
28+
arg.insert(0, '-') if /\A[^\-][^=]*\Z/ =~ arg
2929
end
3030

3131
$make, *rest = Shellwords.shellwords($make)

lib/benchmark.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,13 @@ def /(x); memberwise(:/, x) end
577577

578578
def format(arg0 = nil, *args)
579579
fmtstr = (arg0 || FMTSTR).dup
580-
fmtstr.gsub!(/(%[-+\.\d]*)n/){"#{$1}s" % label}
581-
fmtstr.gsub!(/(%[-+\.\d]*)u/){"#{$1}f" % utime}
582-
fmtstr.gsub!(/(%[-+\.\d]*)y/){"#{$1}f" % stime}
583-
fmtstr.gsub!(/(%[-+\.\d]*)U/){"#{$1}f" % cutime}
584-
fmtstr.gsub!(/(%[-+\.\d]*)Y/){"#{$1}f" % cstime}
585-
fmtstr.gsub!(/(%[-+\.\d]*)t/){"#{$1}f" % total}
586-
fmtstr.gsub!(/(%[-+\.\d]*)r/){"(#{$1}f)" % real}
580+
fmtstr.gsub!(/(%[\-+\.\d]*)n/){"#{$1}s" % label}
581+
fmtstr.gsub!(/(%[\-+\.\d]*)u/){"#{$1}f" % utime}
582+
fmtstr.gsub!(/(%[\-+\.\d]*)y/){"#{$1}f" % stime}
583+
fmtstr.gsub!(/(%[\-+\.\d]*)U/){"#{$1}f" % cutime}
584+
fmtstr.gsub!(/(%[\-+\.\d]*)Y/){"#{$1}f" % cstime}
585+
fmtstr.gsub!(/(%[\-+\.\d]*)t/){"#{$1}f" % total}
586+
fmtstr.gsub!(/(%[\-+\.\d]*)r/){"(#{$1}f)" % real}
587587
arg0 ? Kernel::format(fmtstr, *args) : fmtstr
588588
end
589589

lib/cgi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def stdoutput
236236
url_encoded_string = CGI::escape("string")
237237
=end
238238
def CGI::escape(string)
239-
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
239+
string.gsub(/([^ a-zA-Z0-9_.\-]+)/n) do
240240
'%' + $1.unpack('H2' * $1.size).join('%').upcase
241241
end.tr(' ', '+')
242242
end

lib/date/format.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def self.__strptime(str, fmt, elem)
8080
when '%F'
8181
return unless __strptime(str, '%Y-%m-%d', elem)
8282
when '%G'
83-
return unless str.sub!(/\A([-+]?\d+)/o, '')
83+
return unless str.sub!(/\A([\-+]?\d+)/o, '')
8484
val = $1.to_i
8585
elem[:cwyear] = val
8686
when '%g'
@@ -163,7 +163,7 @@ def self.__strptime(str, fmt, elem)
163163
when '%x'
164164
return unless __strptime(str, '%m/%d/%y', elem)
165165
when '%Y'
166-
return unless str.sub!(/\A([-+]?\d+)/o, '')
166+
return unless str.sub!(/\A([\-+]?\d+)/o, '')
167167
val = $1.to_i
168168
elem[:year] = val
169169
when '%y'
@@ -173,7 +173,7 @@ def self.__strptime(str, fmt, elem)
173173
elem[:year] = val
174174
elem[:cent] ||= if val >= 69 then 19 else 20 end
175175
when '%Z', '%z'
176-
return unless str.sub!(/\A([a-z0-9:+-]+(?:\s+dst\b)?)/io, '')
176+
return unless str.sub!(/\A([a-z0-9:+\-]+(?:\s+dst\b)?)/io, '')
177177
val = $1
178178
elem[:zone] = val
179179
offset = zone_to_diff(val)
@@ -227,7 +227,7 @@ def self._strptime(str, fmt='%F')
227227
def self._parse(str, comp=false)
228228
str = str.dup
229229

230-
str.gsub!(/[^-+.\/:0-9a-z]+/ino, ' ')
230+
str.gsub!(/[^\-+.\/:0-9a-z]+/ino, ' ')
231231

232232
# day
233233
if str.sub!(/(#{PARSE_DAYPAT})\S*/ino, ' ')
@@ -246,7 +246,7 @@ def self._parse(str, comp=false)
246246
(
247247
[a-z]+(?:\s+dst)?\b
248248
|
249-
[-+]\d+(?::?\d+)
249+
[\-+]\d+(?::?\d+)
250250
)
251251
)?
252252
/inox,
@@ -308,7 +308,7 @@ def self._parse(str, comp=false)
308308
end
309309

310310
# iso
311-
elsif str.sub!(/([-+]?\d+)-(\d+)-(-?\d+)/no, ' ')
311+
elsif str.sub!(/([\-+]?\d+)-(\d+)-(-?\d+)/no, ' ')
312312
year = $1.to_i
313313
mon = $2.to_i
314314
mday = $3.to_i
@@ -363,7 +363,7 @@ def self._parse(str, comp=false)
363363

364364
# ddd
365365
elsif str.sub!(
366-
/([-+]?)(\d{4,14})
366+
/([\-+]?)(\d{4,14})
367367
(?:
368368
\s*
369369
T?
@@ -375,7 +375,7 @@ def self._parse(str, comp=false)
375375
(
376376
Z
377377
|
378-
[-+]\d{2,4}
378+
[\-+]\d{2,4}
379379
)
380380
\b
381381
)?
@@ -444,7 +444,7 @@ def self.zone_to_diff(str)
444444
if ZONES.include?(abb)
445445
offset = ZONES[abb]
446446
offset += 3600 if dst
447-
elsif /\A([+-])(\d{2}):?(\d{2})?\Z/no =~ str
447+
elsif /\A([+\-])(\d{2}):?(\d{2})?\Z/no =~ str
448448
offset = $2.to_i * 3600 + $3.to_i * 60
449449
offset *= -1 if $1 == '-'
450450
end

lib/debug.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def debug_command(file, line, id, binding)
425425
b = previous_line ? previous_line - 10 : binding_line - 5
426426
e = b + 9
427427
else
428-
b, e = $1.split(/[-,]/)
428+
b, e = $1.split(/[\-,]/)
429429
if e
430430
b = b.to_i
431431
e = e.to_i

lib/getoptlong.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def set_options(*arguments)
180180
#
181181
next if i == argument_flag
182182
begin
183-
if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
183+
if !i.is_a?(String) || i !~ /^-([^\-]|-.+)$/
184184
raise ArgumentError, "an invalid option `#{i}'"
185185
end
186186
if (@canonical_names.include?(i))

lib/irb/ruby-lex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def identify_number
948948
allow_point = false
949949
when allow_e && "e", allow_e && "E"
950950
type = TkFLOAT
951-
if peek(0) =~ /[+-]/
951+
if peek(0) =~ /[+\-]/
952952
getc
953953
end
954954
allow_e = false

0 commit comments

Comments
 (0)