diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2010-07-19 16:12:03 +0200 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2010-07-19 16:12:03 +0200 |
commit | 231da940da1842740b842a06d126d3562b5b7822 (patch) | |
tree | 2add80022678e65e1d3a354ad1466c494bfc5c90 /poll.rb | |
parent | 51323c7866f43a6edf7196bff5dd90bb55944395 (diff) |
bugfix: htmlid works same as in javascript
Diffstat (limited to 'poll.rb')
-rw-r--r-- | poll.rb | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -25,8 +25,23 @@ require "timepollhead" $KCODE = "u" class String + @@htmlidcache = {} + @@htmlidncache = {} + + # FIXME: htmlid should not depend on the order it is requested def to_htmlID - CGI.escapeHTML(self.gsub(/[^A-Za-z0-9_:.\-]/,".")) + if @@htmlidcache[self] + id = @@htmlidcache[self] + else + id = self.gsub(/[^A-Za-z0-9_:.\-]/,".") + if @@htmlidncache[id] + @@htmlidncache[id] += 1 + id += @@htmlidncache[id].to_s + end + @@htmlidncache[id] = -1 + @@htmlidcache[self] = id + end + return id end end class Poll @@ -510,4 +525,17 @@ class PollTest < Test::Unit::TestCase end end +class StringTest < Test::Unit::TestCase + def test_htmlid + assert_equal("foo.bar.", "foo bar ".to_htmlID); + assert_equal("foo.bar.", "foo bar ".to_htmlID); + assert_equal("foo.bar.0", "foo.bar ".to_htmlID); + assert_equal("foo.bar.00", "foo.bar 0".to_htmlID); + assert_equal("foo.bar.", "foo bar ".to_htmlID); + assert_equal("foo.bar.1", "foo bar.".to_htmlID); + assert_equal("foo.bar.2", "foo?bar.".to_htmlID); + assert_equal("foo.bar.3", "foo bar?".to_htmlID); + assert_equal("foo.bar.2", "foo?bar.".to_htmlID); + end +end end |