Charles -

The merge of your branch "ignored" the class I had previously extracted for 
translating Ruby regexs to Java regexs.  I've attempted to a) correct that 
part, and b) get that "octal" bug working again, but now I'm getting an NPE 
deep in the heart of interpertation.

Could you try the attached patch, and see if you can figure it out?

Thanks.
David
### Eclipse Workspace Patch 1.0
#P jruby
Index: src/org/jruby/RubyRegexp.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/RubyRegexp.java,v
retrieving revision 1.36
diff -u -r1.36 RubyRegexp.java
--- src/org/jruby/RubyRegexp.java	2 Feb 2006 19:51:49 -0000	1.36
+++ src/org/jruby/RubyRegexp.java	4 Feb 2006 13:14:31 -0000
@@ -47,11 +47,9 @@
  * @author  amoore
  */
 public class RubyRegexp extends RubyObject implements ReOptions {
-    private static final Pattern COMMENT_PATTERN = Pattern.compile("\\(\\?#[^)]*\\)");
-    private static final Pattern HEX_SINGLE_DIGIT_PATTERN = Pattern.compile("\\\\x(\\p{XDigit})(?!\\p{XDigit})");
-    private static final Pattern OCTAL_SINGLE_DIGIT_PATTERN = Pattern.compile("\\\\([0-7])(?![0-7])");
-    private static final Pattern OCTAL_MISSING_ZERO_PATTERN = Pattern.compile("\\\\([1-7][0-7]+)");
-    /** Class which represents the multibyte character set code.
+    private static final RegexpTranslator REGEXP_TRANSLATOR = new RegexpTranslator();
+
+	/** Class which represents the multibyte character set code.
 	 * (should be an enum in Java 5.0).
 	 * 
 	 * Warning: THIS IS NOT REALLY SUPPORTED BY JRUBY. 
@@ -140,21 +138,7 @@
     }
 
     public void initialize(String regex, int options) {
-    	int flags = Pattern.MULTILINE;
-        if ((options & RE_OPTION_IGNORECASE) > 0) {
-            flags |= Pattern.CASE_INSENSITIVE;
-        }
-        if ((options & RE_OPTION_EXTENDED) > 0) {
-        	flags |= Pattern.COMMENTS;
-        }
-        if ((options & RE_OPTION_MULTILINE) > 0) {
-        	flags |= Pattern.DOTALL;
-        }
-        regex = COMMENT_PATTERN.matcher(regex).replaceAll("");
-        regex = HEX_SINGLE_DIGIT_PATTERN.matcher(regex).replaceAll("\\\\"+"x0$1");
-        regex = OCTAL_SINGLE_DIGIT_PATTERN.matcher(regex).replaceAll("\\\\"+"0$1");
-        regex = OCTAL_MISSING_ZERO_PATTERN.matcher(regex).replaceAll("\\\\"+"0$1");
-        pattern = Pattern.compile(regex, flags | this.code.flags());
+        pattern = REGEXP_TRANSLATOR.translate(regex, options, code.flags());
     }
 
     public static String quote(String orig) {
Index: src/org/jruby/RegexpTranslator.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/RegexpTranslator.java,v
retrieving revision 1.1
diff -u -r1.1 RegexpTranslator.java
--- src/org/jruby/RegexpTranslator.java	23 Dec 2005 16:23:20 -0000	1.1
+++ src/org/jruby/RegexpTranslator.java	4 Feb 2006 13:14:31 -0000
@@ -13,9 +13,9 @@
 	private static final Pattern SPACE_IN_CHARACTER_CLASS_PATTERN = Pattern.compile("(\\[[^]]*) (.*?])");
 	private static final Pattern COMMENT_PATTERN = Pattern.compile("\\(\\?#[^)]*\\)");
     private static final Pattern HEX_SINGLE_DIGIT_PATTERN = Pattern.compile("\\\\x(\\p{XDigit})(?!\\p{XDigit})");
-    private static final Pattern OCTAL_SINGLE_DIGIT_PATTERN = Pattern.compile("\\\\([0-7])(?![0-7])");
     private static final Pattern OCTAL_THREE_DIGIT_PATTERN = Pattern.compile("\\\\([1-3][0-7]{2})");
-
+    private static final Pattern OCTAL_MISSING_ZERO_PATTERN = Pattern.compile("\\\\([1-7][0-7]{1,2})");
+    
     public Pattern translate(String regex, int options, int javaRegexFlags) {
     	javaRegexFlags |= translateFlags(options);
 		regex = translatePattern(regex, (javaRegexFlags & Pattern.COMMENTS) != 0);
@@ -25,12 +25,13 @@
 	String translatePattern(String regex, boolean commentsAllowed) {
 		regex = COMMENT_PATTERN.matcher(regex).replaceAll("");
 		regex = HEX_SINGLE_DIGIT_PATTERN.matcher(regex).replaceAll("\\\\"+"x0$1");
-		regex = OCTAL_SINGLE_DIGIT_PATTERN.matcher(regex).replaceAll("\\\\"+"0$1");
 		regex = OCTAL_THREE_DIGIT_PATTERN.matcher(regex).replaceAll("\\\\"+"0$1");
+		regex = OCTAL_MISSING_ZERO_PATTERN.matcher(regex).replaceAll("\\\\"+"0$1");
 		if (commentsAllowed) {
 			regex = SPACE_IN_CHARACTER_CLASS_PATTERN.matcher(regex).replaceAll("$1\\\\x20$2");
 			regex = SHARP_IN_CHARACTER_CLASS_PATTERN.matcher(regex).replaceAll("$1\\\\x23$2");
 		}
+		
 		return regex;
 	}
 	
Index: xmlTestBug.rb
===================================================================
RCS file: xmlTestBug.rb
diff -N xmlTestBug.rb
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ xmlTestBug.rb	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,20 @@
+require 'test/unit'
+require 'rexml/document'
+  
+SQL_TAG = <<SQL
+<sql includes="homeoffice">
+</sql>
+SQL
+XML_FILE = <<END_OF_FILE
+<database>
+#{SQL_TAG}
+</database>
+END_OF_FILE
+
+class AdjustTicketsRestTest < Test::Unit::TestCase
+  def testXml
+    doc = REXML::Document.new(XML_FILE) 
+  end
+  
+end
+

Reply via email to