From 58ef7c20880642c88d06b351f8bbaaa291898e58 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 21 Mar 2003 15:13:23 +0000 Subject: [PATCH] * 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 --- ChangeLog | 10 ++++++++++ ext/extmk.rb | 2 +- ext/tk/lib/tk.rb | 18 +++++++++--------- instruby.rb | 2 +- lib/benchmark.rb | 14 +++++++------- lib/cgi.rb | 2 +- lib/date/format.rb | 18 +++++++++--------- lib/debug.rb | 2 +- lib/getoptlong.rb | 2 +- lib/irb/ruby-lex.rb | 2 +- lib/jcode.rb | 2 +- lib/optparse.rb | 18 +++++++++--------- lib/time.rb | 4 ++-- regex.c | 6 +++--- 14 files changed, 56 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f94160667..36b3c93734 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Mar 21 23:40:41 2003 Tanaka Akira + + * 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. + Fri Mar 21 23:23:45 2003 Yukihiro Matsumoto * regex.c (re_compile_pattern): give warning for unescaped square diff --git a/ext/extmk.rb b/ext/extmk.rb index 06a9fd50fc..326310c47f 100644 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -127,7 +127,7 @@ def parse_args() $mflags = Shellwords.shellwords(mflags) if arg = $mflags.first - arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg + arg.insert(0, '-') if /\A[^\-][^=]*\Z/ =~ arg end $make, *rest = Shellwords.shellwords($make) diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 9a15f09989..c24d6150aa 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -605,7 +605,7 @@ module TkCore end def rb_appsend(interp, async, *args) - args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')} + args = args.collect!{|c| _get_eval_string(c).gsub(/[\]\[$"]/, '\\\\\&')} args.push(').to_s"') appsend(interp, async, 'ruby "(', *args) end @@ -620,7 +620,7 @@ module TkCore end def rb_appsend_displayof(interp, win, async, *args) - args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')} + args = args.collect!{|c| _get_eval_string(c).gsub(/[\]\[$"]/, '\\\\\&')} args.push(').to_s"') appsend_displayof(interp, win, async, 'ruby "(', *args) end @@ -1179,14 +1179,14 @@ class TkVariable elsif val.kind_of?(Array) a = [] val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))} - s = '"' + a.join(" ").gsub(/[][$"]/, '\\\\\&') + '"' + s = '"' + a.join(" ").gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) elsif val.kind_of?(Hash) s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ - .gsub(/[][$"]/, '\\\\\&') + '"' + .gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) else - s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"' + s = '"' + _get_eval_string(val).gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; set %s %s', @id, @id, s)) end end @@ -1214,7 +1214,7 @@ class TkVariable def value=(val) begin - s = '"' + _get_eval_string(val).gsub(/[][$"]/, '\\\\\&') + '"' + s = '"' + _get_eval_string(val).gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; set %s %s', @id, @id, s)) rescue if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1" @@ -1226,12 +1226,12 @@ class TkVariable elsif val.kind_of?(Array) a = [] val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))} - s = '"' + a.join(" ").gsub(/[][$"]/, '\\\\\&') + '"' + s = '"' + a.join(" ").gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; unset %s; array set %s %s', @id, @id, @id, s)) elsif val.kind_of?(Hash) s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ - .gsub(/[][$"]/, '\\\\\&') + '"' + .gsub(/[\]\[$"]/, '\\\\\&') + '"' INTERP._eval(format('global %s; unset %s; array set %s %s', @id, @id, @id, s)) else @@ -1438,7 +1438,7 @@ class TkVarAccess= 69 then 19 else 20 end when '%Z', '%z' - return unless str.sub!(/\A([a-z0-9:+-]+(?:\s+dst\b)?)/io, '') + return unless str.sub!(/\A([a-z0-9:+\-]+(?:\s+dst\b)?)/io, '') val = $1 elem[:zone] = val offset = zone_to_diff(val) @@ -227,7 +227,7 @@ class Date def self._parse(str, comp=false) str = str.dup - str.gsub!(/[^-+.\/:0-9a-z]+/ino, ' ') + str.gsub!(/[^\-+.\/:0-9a-z]+/ino, ' ') # day if str.sub!(/(#{PARSE_DAYPAT})\S*/ino, ' ') @@ -246,7 +246,7 @@ class Date ( [a-z]+(?:\s+dst)?\b | - [-+]\d+(?::?\d+) + [\-+]\d+(?::?\d+) ) )? /inox, @@ -308,7 +308,7 @@ class Date end # iso - elsif str.sub!(/([-+]?\d+)-(\d+)-(-?\d+)/no, ' ') + elsif str.sub!(/([\-+]?\d+)-(\d+)-(-?\d+)/no, ' ') year = $1.to_i mon = $2.to_i mday = $3.to_i @@ -363,7 +363,7 @@ class Date # ddd elsif str.sub!( - /([-+]?)(\d{4,14}) + /([\-+]?)(\d{4,14}) (?: \s* T? @@ -375,7 +375,7 @@ class Date ( Z | - [-+]\d{2,4} + [\-+]\d{2,4} ) \b )? @@ -444,7 +444,7 @@ class Date if ZONES.include?(abb) offset = ZONES[abb] offset += 3600 if dst - elsif /\A([+-])(\d{2}):?(\d{2})?\Z/no =~ str + elsif /\A([+\-])(\d{2}):?(\d{2})?\Z/no =~ str offset = $2.to_i * 3600 + $3.to_i * 60 offset *= -1 if $1 == '-' end diff --git a/lib/debug.rb b/lib/debug.rb index 8f2999a3ab..9d49fafac7 100644 --- a/lib/debug.rb +++ b/lib/debug.rb @@ -425,7 +425,7 @@ class Context b = previous_line ? previous_line - 10 : binding_line - 5 e = b + 9 else - b, e = $1.split(/[-,]/) + b, e = $1.split(/[\-,]/) if e b = b.to_i e = e.to_i diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb index 9c8ed09db9..53badc43f3 100644 --- a/lib/getoptlong.rb +++ b/lib/getoptlong.rb @@ -180,7 +180,7 @@ class GetoptLong # next if i == argument_flag begin - if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/ + if !i.is_a?(String) || i !~ /^-([^\-]|-.+)$/ raise ArgumentError, "an invalid option `#{i}'" end if (@canonical_names.include?(i)) diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 26b0b3b7c2..80d392a492 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -948,7 +948,7 @@ class RubyLex allow_point = false when allow_e && "e", allow_e && "E" type = TkFLOAT - if peek(0) =~ /[+-]/ + if peek(0) =~ /[+\-]/ getc end allow_e = false diff --git a/lib/jcode.rb b/lib/jcode.rb index 8e2becc128..df2cd61b3f 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -9,7 +9,7 @@ class String printf STDERR, "feel free for some warnings:\n" if $VERBOSE def _regex_quote(str) - str.gsub(/(\\[][\-\\])|\\(.)|([][\\])/) do + str.gsub(/(\\[\]\[\-\\])|\\(.)|([\]\[\\])/) do $1 || $2 || '\\' + $3 end end diff --git a/lib/optparse.rb b/lib/optparse.rb index d7003c6fa4..1da5ef2cc0 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -965,7 +965,7 @@ Default options, which never appear in option summary. raise ArgumentError, "unsupported argument type: #{o}" when *ArgumentStyle.keys style = notwice(ArgumentStyle[o], style, 'style') - when /^--no-([^][=\s]*)(.+)?/ + when /^--no-([^\]\[=\s]*)(.+)?/ q, a = $1, $2 o = notwice(a ? Object : TrueClass, klass, 'type') not_pattern, not_conv = search(:atype, o) unless not_style @@ -975,7 +975,7 @@ Default options, which never appear in option summary. ldesc << "--no-#{q}" long << 'no-' + (q = q.downcase) nolong << q - when /^--\[no-\]([^][=\s]*)(.+)?/ + when /^--\[no-\]([^\]\[=\s]*)(.+)?/ q, a = $1, $2 o = notwice(a ? Object : TrueClass, klass, 'type') if a @@ -987,7 +987,7 @@ Default options, which never appear in option summary. not_pattern, not_conv = search(:atype, FalseClass) unless not_style not_style = Switch::NoArgument nolong << 'no-' + o - when /^--([^][=\s]*)(.+)?/ + when /^--([^\]\[=\s]*)(.+)?/ q, a = $1, $2 if a o = notwice(NilClass, klass, 'type') @@ -1346,14 +1346,14 @@ Default options, which never appear in option summary. hex = 'x[\da-f]+(?:_[\da-f]+)*' octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})" integer = "#{octal}|#{decimal}" - accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s| Integer(s) if s} + accept(Integer, %r"\A[\-+]?(?:#{integer})"io) {|s| Integer(s) if s} =begin : Float Float number format, and converts to (({Float})). =end #'#"#`# - float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?" - floatpat = %r"\A[-+]?#{float}"io + float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[\\-+]?#{decimal})?" + floatpat = %r"\A[\-+]?#{float}"io accept(Float, floatpat) {|s| s.to_f if s} =begin @@ -1361,13 +1361,13 @@ Default options, which never appear in option summary. Generic numeric format, and converts to (({Integer})) for integer format, (({Float})) for float format. =end #'#"#`# - accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s| eval(s) if s} + accept(Numeric, %r"\A[\-+]?(?:#{octal}|#{float})"io) {|s| eval(s) if s} =begin : OptionParser::DecimalInteger Decimal integer format, to be converted to (({Integer})). =end #'#"#`# - DecimalInteger = /\A[-+]?#{decimal}/io + DecimalInteger = /\A[\-+]?#{decimal}/io accept(DecimalInteger) {|s| s.to_i if s} =begin @@ -1375,7 +1375,7 @@ Default options, which never appear in option summary. Ruby/C like octal/hexadecimal/binary integer format, to be converted to (({Integer})). =end #'#"#`# - OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io + OctalInteger = /\A[\-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io accept(OctalInteger) {|s| s.oct if s} =begin diff --git a/lib/time.rb b/lib/time.rb index f3e18d7c28..4c9d8a526e 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -69,9 +69,9 @@ class Time def zone_offset(zone, year=Time.now.year) off = nil zone = zone.upcase - if /\A([-+])(\d\d):?(\d\d)\z/ =~ zone + if /\A([\-+])(\d\d):?(\d\d)\z/ =~ zone off = ($1 == '-' ? -1 : 1) * ($2.to_i * 60 + $3.to_i) * 60 - elsif /\A[-+]\d\d\z/ =~ zone + elsif /\A[\-+]\d\d\z/ =~ zone off = zone.to_i * 3600 elsif ZoneOffset.include?(zone) off = ZoneOffset[zone] * 3600 diff --git a/regex.c b/regex.c index 7ae16cf121..c81c140acc 100644 --- a/regex.c +++ b/regex.c @@ -185,7 +185,7 @@ static int current_mbctype = MBCTYPE_ASCII; #ifdef RUBY #include "util.h" -# re_warning(x) rb_warn(x) +# define re_warning(x) rb_warn(x) #endif #ifndef re_warning @@ -1489,6 +1489,8 @@ re_compile_pattern(pattern, size, bufp) if (c == '-') re_warning("character class has `-' without escape"); + if (c == '[' && *p != ':') + re_warning("character class has `[' without escape"); /* \ escapes characters when inside [...]. */ if (c == '\\') { @@ -1695,8 +1697,6 @@ re_compile_pattern(pattern, size, bufp) } } else if (had_mbchar == 0 && (!current_mbctype || !had_num_literal)) { - if (c == '[') - re_warning("character class has `[' without escape"); SET_LIST_BIT(c); had_num_literal = 0; }