2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails スラッシュを複数挟んでもnot foundにならない

Posted at

同僚から

Rails のルーティングは連続するスラッシュは単一扱いされるらしい。
localhost:3000/utilities///////hoge/39
の様にスラッシュを複数挟んでもnot foundにならないのはなんでなん?

という質問を受けたので、備忘録として書いておきます。

僕が調べた感じ、railsの名前解決の流れは
https://qiita.com/kkyouhei/items/1203f5aa521c065a7097
らしい。

そこで通る
Journey::Router::Utils.normalize_path(path)
にて

 def self.normalize_path(path) 
     path = "/#{path}"
     path.squeeze!('/')
     path.sub!(%r{/+\Z}, '')
     path = '/' if path == ''
     path
 end

引数に含まれる文字が複数並んでいたら 1 文字にまとめる

.squeeze!('/')をしているから

履歴にも残してはいけないものを書いていたので上げ直しです。
ごめんなさい

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?