module Roda::RodaPlugins::MultibyteStringMatcher

The multibyte_string_matcher plugin allows multibyte strings to be used in matchers. Roda’s default string matcher does not handle multibyte strings for performance reasons.

As browsers send multibyte characters in request paths URL escaped, so this also loads the unescape_path plugin to unescape the paths.

plugin :multibyte_string_matcher

path = "\xD0\xB8".force_encoding('UTF-8')
route do |r|
  r.get path do
    # GET /\xD0\xB8 (request.path in UTF-8 format)
  end

  r.get /y-(#{path})/u do |x|
    # GET /y-\xD0\xB8 (request.path in UTF-8 format)
    x => "\xD0\xB8".force_encoding('BINARY')
  end
end