Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 1c4a906

Browse files
committed
More safely build filenames
This avoids an error I was getting while parsing http://localhost:8095/foo `invalid value for Integer(): ":"`
1 parent 377e6a8 commit 1c4a906

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

lib/openid/store/filesystem.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,11 @@ def mktemp
230230
# create a safe filename from a url
231231
def filename_escape(s)
232232
s = '' if s.nil?
233-
filename_chunks = []
234-
s.split('').each do |c|
235-
if @@FILENAME_ALLOWED.index(c)
236-
filename_chunks << c
237-
else
238-
filename_chunks << sprintf("_%02X", c.bytes.first)
239-
end
240-
end
241-
filename_chunks.join("")
233+
filename_chunks = s.each_char.flat_map {|c|
234+
@@FILENAME_ALLOWED.include?(c) ? c : c.bytes.map {|b|
235+
"_%02X" % b
236+
}
237+
}.join
242238
end
243239

244240
def safe64(s)

0 commit comments

Comments
 (0)