{"action":"created","issue":{"url":"https://api.github.com/repos/jruby/jruby/issues/2998","labels_url":"https://api.github.com/repos/jruby/jruby/issues/2998/labels{/name}","comments_url":"https://api.github.com/repos/jruby/jruby/issues/2998/comments","events_url":"https://api.github.com/repos/jruby/jruby/issues/2998/events","html_url":"https://github.com/jruby/jruby/issues/2998","id":81971312,"number":2998,"title":"CRITICAL! Regular expression hang with string containing umlaut characters","user":{"login":"pinnamur","id":2413570,"avatar_url":"https://avatars.githubusercontent.com/u/2413570?v=3","gravatar_id":"","url":"https://api.github.com/users/pinnamur","html_url":"https://github.com/pinnamur","followers_url":"https://api.github.com/users/pinnamur/followers","following_url":"https://api.github.com/users/pinnamur/following{/other_user}","gists_url":"https://api.github.com/users/pinnamur/gists{/gist_id}","starred_url":"https://api.github.com/users/pinnamur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinnamur/subscriptions","organizations_url":"https://api.github.com/users/pinnamur/orgs","repos_url":"https://api.github.com/users/pinnamur/repos","events_url":"https://api.github.com/users/pinnamur/events{/privacy}","received_events_url":"https://api.github.com/users/pinnamur/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jruby/jruby/labels/core","name":"core","color":"02e10c"},{"url":"https://api.github.com/repos/jruby/jruby/labels/encoding","name":"encoding","color":"671716"},{"url":"https://api.github.com/repos/jruby/jruby/labels/JRuby%201.7.x","name":"JRuby 1.7.x","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/jruby/jruby/milestones/33","html_url":"https://github.com/jruby/jruby/milestones/JRuby%201.7.21","labels_url":"https://api.github.com/repos/jruby/jruby/milestones/33/labels","id":958668,"number":33,"title":"JRuby 1.7.21","description":"","creator":{"login":"enebo","id":19819,"avatar_url":"https://avatars.githubusercontent.com/u/19819?v=3","gravatar_id":"","url":"https://api.github.com/users/enebo","html_url":"https://github.com/enebo","followers_url":"https://api.github.com/users/enebo/followers","following_url":"https://api.github.com/users/enebo/following{/other_user}","gists_url":"https://api.github.com/users/enebo/gists{/gist_id}","starred_url":"https://api.github.com/users/enebo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enebo/subscriptions","organizations_url":"https://api.github.com/users/enebo/orgs","repos_url":"https://api.github.com/users/enebo/repos","events_url":"https://api.github.com/users/enebo/events{/privacy}","received_events_url":"https://api.github.com/users/enebo/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":11,"state":"open","created_at":"2015-01-30T18:43:27Z","updated_at":"2015-05-28T17:22:25Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2015-05-28T15:04:03Z","updated_at":"2015-05-28T18:07:21Z","closed_at":null,"body":"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\r\n\r\n```\r\npublic class RubyRegexTest\r\n{\r\n\r\n\tpublic static void main(String[] args)\r\n\t{\r\n\t\t// System.out.println(\"ütest\");\r\n\r\n\t\tRuby runtime = Ruby.newInstance();\r\n\t\tString regPattern = \"(?-mix:^(.*\\\\*\\\\/)?\\\\s*(\\\\}|\\\\))([^{]*\\\\{)?([;,]?\\\\s*|\\\\.[^{]*|\\\\s*\\\\)[;\\\\s]*)$)\";\r\n\t\tRubyRegexp regexp = RubyRegexp.newRegexp(runtime, regPattern, new RegexpOptions(KCode.UTF8, true));\r\n\r\n\t\tSystem.out.println(matchesRegexp(regexp, \"console.log('testü');\"));\r\n\t\tSystem.out.println(\"Done!\");\r\n\r\n\t}\r\n\r\n\tprotected static boolean matchesRegexp(RubyRegexp regexp, String lineContent)\r\n\t{\r\n\t\tif (regexp == null)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\tRuby runtime = regexp.getRuntime();\r\n\t\tRubyString string = runtime.newString(lineContent);\r\n\t\tIRubyObject matcher = regexp.match_m(regexp.getRuntime().getCurrentContext(), string);\r\n\t\treturn !matcher.isNil();\r\n\t}\r\n\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/jruby/jruby/issues/comments/106539676","html_url":"https://github.com/jruby/jruby/issues/2998#issuecomment-106539676","issue_url":"https://api.github.com/repos/jruby/jruby/issues/2998","id":106539676,"user":{"login":"headius","id":10135,"avatar_url":"https://avatars.githubusercontent.com/u/10135?v=3","gravatar_id":"","url":"https://api.github.com/users/headius","html_url":"https://github.com/headius","followers_url":"https://api.github.com/users/headius/followers","following_url":"https://api.github.com/users/headius/following{/other_user}","gists_url":"https://api.github.com/users/headius/gists{/gist_id}","starred_url":"https://api.github.com/users/headius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/headius/subscriptions","organizations_url":"https://api.github.com/users/headius/orgs","repos_url":"https://api.github.com/users/headius/repos","events_url":"https://api.github.com/users/headius/events{/privacy}","received_events_url":"https://api.github.com/users/headius/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T18:07:21Z","updated_at":"2015-05-28T18:07:21Z","body":"Ahh, I ses, this is code from Aptana's Ruby tooling. I expect that code has not been updated in some time.\r\n\r\nI do have another workaround, if there's no way to avoid using these RubyRegexp API calls:\r\n\r\n```java\r\n        RubyInstanceConfig config = new RubyInstanceConfig();\r\n        config.setCompatVersion(CompatVersion.RUBY1_8);\r\n        Ruby runtime = Ruby.newInstance(config);\r\n```\r\n\r\nThis creates the new runtime explicitly in Ruby 1.8.7 mode, avoiding the behavioral conflicts with Ruby 1.9.3 mode's encoding support. Your example runs to completion with this change, while still using match_m.\r\n\r\nI must caution, however, that these are very much internal APIs not intended to be used outside of JRuby. They're public only because we need to use them across packages. And in JRuby 9k, match_m and match_m19 are equivalent and only use the encoding-aware logic, which may cause problems for you in the future. A better solution that uses our regex engine (https://github.com/jruby/joni) directly, or which uses our embedding APIs to run this logic as Ruby code, would both be more robust than this."}}