Skip to content

Fix httpd error in CJK directory#2998

Closed
znz wants to merge 1 commit intoruby:masterfrom
znz:fix-httpd-error-in-cjk-path
Closed

Fix httpd error in CJK directory#2998
znz wants to merge 1 commit intoruby:masterfrom
znz:fix-httpd-error-in-cjk-path

Conversation

@znz
Copy link
Copy Markdown
Member

@znz znz commented Apr 3, 2020

@jeremyevans
Copy link
Copy Markdown
Contributor

This looks good, but I think it should be filed upstream: https://github.com/ruby/webrick


def set_filename(req, res)
res.filename = @root.dup
res.filename = @root.b
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- filehandler.rb.old	2020-04-09 09:49:57.536780938 +0800
+++ filehandler.rb	2020-04-09 09:58:41.387264503 +0800
@@ -520,6 +520,7 @@
           s =  "<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}#{query if name.end_with?('/')}\">#{HTMLUtils::escape(dname)}</A></TD>"
           s << "<TD class=\"mtime\">" << (time ? time.strftime("%Y/%m/%d %H:%M") : "") << "</TD>"
           s << "<TD class=\"size\">" << (size >= 0 ? size.to_s : "-") << "</TD></TR>\n"
+          s.force_encoding 'ASCII-8BIT'
           res.body << s
         }
         res.body << "</TBODY></TABLE>"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with CJK filename in CJK directory (as DocumentRoot), but s.force_encoding 'ASCII-8BIT' is not required.
How to reproduce the case to need s.force_encoding 'ASCII-8BIT'?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require 'webrick'

d="\u3042"
Dir.mkdir(d) if not File.exist? d
`echo CJK_file > #{d}/#{d}.txt`
port = 8080
config = { :DocumentRoot => "." , :Port => port }
s=WEBrick::HTTPServer.new(config)
Thread.new {s.start }
p url = "http://127.0.0.1:#{port}/%E3%81%82/%E3%81%82.txt" # OK                                
`curl #{url} `
p url = "http://127.0.0.1:#{port}/%E3%81%82/" # ERR
`curl #{url}`
sleep 30

@jeremyevans
Copy link
Copy Markdown
Contributor

I filed this upstream: ruby/webrick#42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants