Skip to content

CRITICAL! Regular expression hang with string containing umlaut characters #2998

Closed
@pinnamur

Description

@pinnamur

If the string contain umlaut characters, then JRuby hangs while trying to match the regular expression pattern. The below code snippet always hang with JRuby 1.7.20

public class RubyRegexTest
{

    public static void main(String[] args)
    {
        // System.out.println("ütest");

        Ruby runtime = Ruby.newInstance();
        String regPattern = "(?-mix:^(.*\\*\\/)?\\s*(\\}|\\))([^{]*\\{)?([;,]?\\s*|\\.[^{]*|\\s*\\)[;\\s]*)$)";
        RubyRegexp regexp = RubyRegexp.newRegexp(runtime, regPattern, new RegexpOptions(KCode.UTF8, true));

        System.out.println(matchesRegexp(regexp, "console.log('testü');"));
        System.out.println("Done!");

    }

    protected static boolean matchesRegexp(RubyRegexp regexp, String lineContent)
    {
        if (regexp == null)
        {
            return false;
        }
        Ruby runtime = regexp.getRuntime();
        RubyString string = runtime.newString(lineContent);
        IRubyObject matcher = regexp.match_m(regexp.getRuntime().getCurrentContext(), string);
        return !matcher.isNil();
    }

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions