Patches: Browse | Submit New | Admin

[#6366] irb: Fix for bug 3245

Date:
2006-10-27 22:50
Priority:
3
Submitted By:
Dominic Cooney (dcooney)
Assigned To:
Nobody (None)
Category:
Developer Tools/Libs
State:
Open
Summary:
irb: Fix for bug 3245

Detailed description
RubyLex.read_escape doesn't discriminate whether it is lexing a ' or " string. For most escapes the existing code
just happens to work; however it always consumes at least one character after \c. This means in '\c', RubyLex misses
the end of the string and keeps lexing.

This patch makes read_escape only treat \\ and \' as escapes when lexing a ' (or %q) string.

read_escape arguably should ungetc the \ when the following character isn't \ or ' when lexing a ' or %q string, because
a single \ isn't an escape, however I haven't implemented this.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-06-13 15:29
Sender: Dominic Cooney

That looks fine. Sorry for so much reformatting in the
original patch. I assumed sticking a return in the middle of
the function was bad style.
Date: 2007-06-13 06:32
Sender: Ryan Davis

I've reworked the diff into the following. Does it still look
acceptable to you?

Index: lib/irb/ruby-lex.rb
=================================================================
==
--- lib/irb/ruby-lex.rb	(revision 12516)
+++ lib/irb/ruby-lex.rb	(working copy)
@@ -1099,6 +1099,16 @@
   end
   
   def read_escape
+    if @ltype == "'" then
+      case ch = getc
+      when "\\", "'"
+        # do nothing
+      else
+        ungetc ch
+      end
+      return
+    end
+
     case ch = getc
     when "\n", "\r", "\f"
     when "\\", "n", "t", "r",
"f", "v", "a", "e",
"b", "s" #"

Date: 2007-06-13 06:11
Sender: Ryan Davis

I really wish you'd only addressed the problem and not the whitespace
in this patch...

Attached Files:

Name Description Download
3245-ruby-1.9-changes.patch Fix against ruby 1.9 Download

Changes:

Field Old Value Date By
assigned_tozenspider2009-02-18 03:29zenspider
resolution_idNone2007-06-13 06:32zenspider
artifact_group_idv1.9.x2007-06-13 06:32zenspider
assigned_tonone2007-06-13 06:08zenspider
category_idMisc / Other Standard Library2007-05-30 04:16zenspider
summaryFix for bug 32452007-05-30 04:16zenspider
category_idDB / File Formats2007-05-30 03:50zenspider
artifact_group_idNone2007-05-30 03:41zenspider
File Added900: 3245-ruby-1.9-changes.patch2006-10-27 22:50dcooney