Last active
July 23, 2016 06:24
-
-
Save chiepomme/80c1cc24dde97d1d59225743d7437e43 to your computer and use it in GitHub Desktop.
A monkey patch for Jekyll to use non-ascii post title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "webrick" | |
# put this file to [your jekyll root]/_plugins/non-ascii-filename.rb | |
module Jekyll | |
module Commands | |
class Serve | |
class Servlet < WEBrick::HTTPServlet::FileHandler | |
# original: webrick/httpservlet/filehandler.rb | |
def prevent_directory_traversal(req, res) | |
# just change encoding "filesystem" to "utf-8" | |
path = req.path_info.dup.force_encoding(Encoding.find("utf-8")) | |
if trailing_pathsep?(req.path_info) | |
expanded = File.expand_path(path + "x") | |
expanded.chop! | |
else | |
expanded = File.expand_path(path) | |
end | |
expanded.force_encoding(req.path_info.encoding) | |
req.path_info = expanded | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment