Permalink
Browse files

JRUBY-5924: Wrong Behavior at MatchData#end and Strings with special …

…characters (logic/patch by Everton J. Carpes)
  • Loading branch information...
1 parent 4dcacfd commit 0cef21e0c8d5c39fd7f978af2a6a31a4528aa647 @enebo enebo committed Aug 23, 2011
Showing with 15 additions and 1 deletion.
  1. +7 −1 src/org/jruby/RubyMatchData.java
  2. +8 −0 test/test_regexp_1_9.rb
@@ -112,13 +112,19 @@ public int compareTo(Object o) {
}
}
+ // FIXME: many regs == null checks...some part of this should be refactored into multiple methods
private void updateCharOffset() {
if (charOffsetUpdated) return;
int numRegs = regs == null ? 1 : regs.numRegs;
if (charOffsets == null || charOffsets.numRegs < numRegs) charOffsets = new Region(numRegs);
- Pair[]pairs = new Pair[numRegs * 2];
+ int numPairs = 1;
+ if (regs != null) {
+ for (;regs.beg[numPairs] >= 0; numPairs++) {}
+ }
+
+ Pair[] pairs = new Pair[numPairs * 2];
for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair();
int numPos = 0;
@@ -12,4 +12,12 @@ def test_dstr_with_unicode_class
atext = "[#{letter}]"
assert_nothing_raised { /#{atext}/ }
end
+
+ # JRUBY-5924
+ def test_matchdata_end_position_on_unicode_strings
+ rails_scriptlet_re = /(?m-ix:<%(=+|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?)/
+ match = rails_scriptlet_re.match "<%= @user %> á"
+
+ assert_equal 12, match.end(0)
+ end
end

0 comments on commit 0cef21e

Please sign in to comment.