From a2fe07433fec6c9f52f1ea36d7ef53bcd7c095a6 Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Mon, 26 Oct 2009 15:56:00 +0100 Subject: fix encoding issue when creating poll with strange characters --- charset.rb | 10 +++++----- config_poll.rb | 12 +++++++----- index.cgi | 53 ++++++++++++++++++++++++++--------------------------- participate.rb | 12 +++++++----- remove_poll.rb | 12 +++++++----- 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/charset.rb b/charset.rb index 07aedaf..5535844 100644 --- a/charset.rb +++ b/charset.rb @@ -4,10 +4,10 @@ # see License # ################################ -$utfcookie = CGI::Cookie.new("utf", "true") -$utfcookie.path = "/" +utfcookie = CGI::Cookie.new("utf", "true") +utfcookie.path = "/" if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii") - $utfcookie.expires = Time.now+1*60*60*24*365 + utfcookie.expires = Time.now+1*60*60*24*365 UTFASCII = "Change Charset to plain ASCII" YES = CGI.escapeHTML('✔') @@ -23,7 +23,7 @@ if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii") EDIT = CGI.escapeHTML("✍") DELETE = CGI.escapeHTML("⌧") else - $utfcookie.expires = Time.now-1*60*60*24*36 + utfcookie.expires = Time.now-1*60*60*24*36 UTFASCII = "If you see all these characters: #{CGI.escapeHTML('✔✘?–↞←→↠✍⌧')} you can safely change the charset to UTF-8" YES = CGI.escapeHTML('OK') @@ -39,4 +39,4 @@ else EDIT = CGI.escapeHTML("edit") DELETE = CGI.escapeHTML("delete") end - +$header["cookie"] = utfcookie diff --git a/config_poll.rb b/config_poll.rb index 566ca3a..563816b 100755 --- a/config_poll.rb +++ b/config_poll.rb @@ -13,10 +13,11 @@ require "cgi" if __FILE__ == $0 $cgi = CGI.new +$header = {} -TYPE = "text/html" -#TYPE = "application/xhtml+xml" -CHARSET = "utf-8" +$header["type"] = "text/html" +#$header["type"] = "application/xhtml+xml" +$header["charset"] = "utf-8" $htmlout = < - + dudle - config - #{table.name} @@ -220,6 +221,7 @@ $htmlout += "" $htmlout += "" -$cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] => "no-cache" +$cgi.out($header){$htmlout} end diff --git a/index.cgi b/index.cgi index 5904478..1bb3c05 100755 --- a/index.cgi +++ b/index.cgi @@ -13,10 +13,10 @@ require "cgi" if __FILE__ == $0 $cgi = CGI.new - -TYPE = "text/html" -#TYPE = "application/xhtml+xml" -CHARSET = "utf-8" +$header = {} +$header["type"] = "text/html" +#$header["type"] = "application/xhtml+xml" +$header["charset"] = "utf-8" $htmlout = < dudle - + HEAD @@ -49,9 +49,12 @@ HEAD $htmlout += "

dudle

" if $cgi.include?("create_poll") - SITE=$cgi["create_poll"].gsub(/^\//,"") - unless File.exist?(SITE) - Dir.mkdir(SITE) + SITE=$cgi["create_poll"] + if SITE.include?("/") + createnotice = "
Error: The character '/' is not allowed.
" + elsif File.exist?(SITE) + createnotice = "
Error: This poll already exists!
" + else Dir.mkdir(SITE) Dir.chdir(SITE) VCS.init File.symlink("../participate.rb","index.cgi") @@ -72,21 +75,16 @@ if $cgi.include?("create_poll") TimePoll.new SITE end Dir.chdir("..") - $cgi.out("status" => "REDIRECT", - "Location" => "#{SITEURL}#{SITE}/", - "type" => TYPE, - "charset" => CHARSET, - "cookie" => $utfcookie, - "Cache-Control" => "no-cache"){ - "The poll was created successfully. The link to your new poll is:
#{SITEURL}#{SITE}" - } - exit - else - createnotice = "
Error: This poll already exists!
" + escapedsite = SITEURL + CGI.escapeHTML(CGI.escape(SITE)) + "/" + escapedsite.gsub!("+"," ") + $header["status"] = "REDIRECT" + $header["Location"] = escapedsite + $htmlout = "The poll was created successfully. The link to your new poll is:
#{escapedsite}" end end -$htmlout += <
Config #{UTFASCII} @@ -94,13 +92,13 @@ $htmlout += < CHARSET -$htmlout += <Create New Poll
- + @@ -118,15 +116,16 @@ $htmlout += <
Type:
-#{createnotice}
CREATE -$htmlout += NOTICE -$htmlout += "" + $htmlout += NOTICE + $htmlout += "" -$htmlout += "" + $htmlout += "" +end -$cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] = "no-cache" +$cgi.out($header){$htmlout} end diff --git a/participate.rb b/participate.rb index 7937ffc..57ecedf 100755 --- a/participate.rb +++ b/participate.rb @@ -13,10 +13,11 @@ require "cgi" if __FILE__ == $0 $cgi = CGI.new +$header = {} -TYPE = "text/html" -#TYPE = "application/xhtml+xml" -CHARSET = "utf-8" +$header["type"] = "text/html" +#$header["type"] = "application/xhtml+xml" +$header["charset"] = "utf-8" $htmlout = < - + dudle - #{table.name} @@ -122,5 +123,6 @@ $htmlout += "" $htmlout += "" -$cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] = "no-cache" +$cgi.out($header){$htmlout} end diff --git a/remove_poll.rb b/remove_poll.rb index 3a0ebb1..542303d 100755 --- a/remove_poll.rb +++ b/remove_poll.rb @@ -19,10 +19,11 @@ require "ftools" if __FILE__ == $0 $cgi = CGI.new +$header = {} -TYPE = "text/html" -#TYPE = "application/xhtml+xml" -CHARSET = "utf-8" +$header["type"] = "text/html" +#$header["type"] = "application/xhtml+xml" +$header["charset"] = "utf-8" POLL = File.basename(File.expand_path(".")) @@ -31,7 +32,7 @@ $htmlout = < - + dudle - delete - #{POLL} @@ -86,6 +87,7 @@ $htmlout += "" $htmlout += "" -$cgi.out("type" => TYPE ,"charset" => CHARSET, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] = "no-cache" +$cgi.out($header){$htmlout} end -- cgit v1.2.3