diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-10-26 15:56:00 +0100 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-10-26 15:56:00 +0100 |
commit | a2fe07433fec6c9f52f1ea36d7ef53bcd7c095a6 (patch) | |
tree | 82b528d3ec6331d4424b3b21f91ca25b3cc3cfb5 | |
parent | 985631b3cbe7a34854f3888a453cf6e9f3d6199e (diff) |
fix encoding issue when creating poll with strange characters
-rw-r--r-- | charset.rb | 10 | ||||
-rwxr-xr-x | config_poll.rb | 12 | ||||
-rwxr-xr-x | index.cgi | 53 | ||||
-rwxr-xr-x | participate.rb | 12 | ||||
-rwxr-xr-x | remove_poll.rb | 12 |
5 files changed, 52 insertions, 47 deletions
@@ -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 = "<a href='?ascii' style='text-decoration:none'>Change Charset to plain ASCII</a>" 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 = "<a href='?utf' style='text-decoration:none'>If you see all these characters: #{CGI.escapeHTML('✔✘?–↞←→↠✍⌧')} you can safely change the charset to UTF-8</a>" 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 = <<HEAD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" @@ -118,7 +119,7 @@ end $htmlout += <<HTMLHEAD <head> - <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> + <meta http-equiv="Content-Type" content="#{$header["type"]}; charset=#{$header["charset"]}" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>dudle - config - #{table.name}</title> <link rel="stylesheet" type="text/css" href="../dudle.css" title="default"/> @@ -220,6 +221,7 @@ $htmlout += "</div></body>" $htmlout += "</html>" -$cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] => "no-cache" +$cgi.out($header){$htmlout} end @@ -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 = <<HEAD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" @@ -39,7 +39,7 @@ require "timepoll" $htmlout += <<HEAD <head> <title>dudle</title> - <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> + <meta http-equiv="Content-Type" content="#{$header["type"]}; charset=#{$header["charset"]}" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link rel="stylesheet" type="text/css" href="dudle.css" title="default"/> HEAD @@ -49,9 +49,12 @@ HEAD $htmlout += "</head><body id='main'><h1>dudle</h1>" 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 = "<div class='error'>Error: The character '/' is not allowed.</div>" + elsif File.exist?(SITE) + createnotice = "<div class='error'>Error: This poll already exists!</div>" + 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:<br /><a href='#{SITEURL}#{SITE}'>#{SITEURL}#{SITE}</a>" - } - exit - else - createnotice = "<div class='error'>Error: This poll already exists!</div>" + 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:<br /><a href=\"#{escapedsite}\">#{escapedsite}</a>" end end -$htmlout += <<CHARSET +unless $header["status"] == "REDIRECT" + $htmlout += <<CHARSET <div id='config'> <fieldset><legend>Config</legend> #{UTFASCII} @@ -94,13 +92,13 @@ $htmlout += <<CHARSET </div> CHARSET -$htmlout += <<CREATE + $htmlout += <<CREATE <fieldset><legend>Create New Poll</legend> <form method='post' action='.'> <table> <tr> <td class='create_poll'><label title="#{poll_name_tip = "the name equals the link under which you receive the poll"}" for="poll_name">Name:</label></td> - <td class='create_poll'><input title="#{poll_name_tip}" id="poll_name" size='16' type='text' name='create_poll' /></td> + <td class='create_poll'><input title="#{poll_name_tip}" id="poll_name" size='16' type='text' name='create_poll' value="#{CGI.escapeHTML($cgi["create_poll"])}" /></td> </tr> <tr> <td>Type:</td> @@ -118,15 +116,16 @@ $htmlout += <<CREATE </tr> </table> </form> -#{createnotice} </fieldset> CREATE -$htmlout += NOTICE -$htmlout += "</body>" + $htmlout += NOTICE + $htmlout += "</body>" -$htmlout += "</html>" + $htmlout += "</html>" +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 = <<HEAD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" @@ -60,7 +61,7 @@ end $htmlout += <<HEAD <head> - <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> + <meta http-equiv="Content-Type" content="#{$header["type"]}; charset=#{$header["charset"]}" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>dudle - #{table.name}</title> <link rel="stylesheet" type="text/css" href="../dudle.css" title="default"/> @@ -122,5 +123,6 @@ $htmlout += "</div></body>" $htmlout += "</html>" -$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 = <<HEAD "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> - <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> + <meta http-equiv="Content-Type" content="#{$header["type"]}; charset=#{$header["charset"]}" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>dudle - delete - #{POLL}</title> <link rel="stylesheet" type="text/css" href="../dudle.css" title="default"/> @@ -86,6 +87,7 @@ $htmlout += "</body>" $htmlout += "</html>" -$cgi.out("type" => TYPE ,"charset" => CHARSET, "Cache-Control" => "no-cache"){$htmlout} +$header["Cache-Control"] = "no-cache" +$cgi.out($header){$htmlout} end |