Sha256: 4b89dbaabe83f2add65cc4d3e34c86cb9733f9b3639ac146b453d2137592b443

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require_relative "../spec_helper"

describe "multibyte_string_matcher plugin" do 
  it "uses multibyte safe string matching" do
    str = "\xD0\xB8".dup.force_encoding('UTF-8')
    app(:unescape_path) do |r|
      r.is String do |s|
        s
      end

      r.is(Integer, /(#{str})/u) do |_, a|
        a
      end

      r.is(Integer, Integer, str) do
        'm'
      end

      r.is(Integer, str, Integer) do
        'n'
      end
    end

    body('/%D0%B8').must_equal str
    body('/1/%D0%B8').must_equal str
    status('/1/2/%D0%B8').must_equal 404
    status('/1/%D0%B8/2').must_equal 404

    status('/1/%D0%B9').must_equal 404
    status('/1/2/%D0%B9').must_equal 404
    status('/1/%D0%B9/2').must_equal 404

    @app.plugin :multibyte_string_matcher

    body('/%D0%B8').must_equal str
    body('/1/%D0%B8').must_equal str
    body('/1/2/%D0%B8').must_equal 'm'
    body('/1/%D0%B8/2').must_equal 'n'

    status('/1/%D0%B9').must_equal 404
    status('/1/2/%D0%B9').must_equal 404
    status('/1/%D0%B9/2').must_equal 404
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin/multibyte_string_matcher_spec.rb
roda-3.27.0 spec/plugin/multibyte_string_matcher_spec.rb