Skip to content

Commit

Permalink
Fix bug with apostrophes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickael Riga committed Aug 11, 2011
1 parent 0032667 commit 4d95cfc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -304,6 +304,7 @@ CHANGE LOG
0.0.5 Crushyform method guesses the enctype
0.0.6 Human name for classes and label for new records
0.0.7 Fix `Model#to_label`
0.0.8 Fix bug with apostrophe in text fields

COPYRIGHT
=========
Expand Down
4 changes: 2 additions & 2 deletions lib/sequel_crushyform.rb
@@ -1,7 +1,7 @@
module ::Sequel::Plugins::Crushyform

module ClassMethods
def crushyform_version; [0,0,7]; end
def crushyform_version; [0,0,8]; end
# Schema
def crushyform_schema
@crushyform_schema ||= default_crushyform_schema
Expand All @@ -24,7 +24,7 @@ def crushyform_types
@crushyform_types ||= {
:none => proc{''},
:string => proc do |m,c,o|
"<input type='%s' name='%s' value='%s' id='%s' class='%s' %s />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:required]]
"<input type='%s' name='%s' value=\"%s\" id='%s' class='%s' %s />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:required]]
end,
:boolean => proc do |m,c,o|
crushid = m.crushyid_for(c)
Expand Down
2 changes: 1 addition & 1 deletion sequel-crushyform.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'sequel-crushyform'
s.version = "0.0.7"
s.version = "0.0.8"
s.platform = Gem::Platform::RUBY
s.summary = "A Sequel plugin that helps building forms"
s.description = "A Sequel plugin that helps building forms. It basically does them for you so that you can forget about the boring part. The kind of thing which is good to have in your toolbox for building a CMS."
Expand Down
16 changes: 10 additions & 6 deletions test/spec_crushyform.rb
Expand Up @@ -268,6 +268,10 @@ class WithAccronymYMCAName < ::Sequel::Model; end
Attached.new.crushyfield(:title, {:type=>:none}).should==''
end

should 'wrap textfileds with double quotes in order to allow apostrophes' do
Haiku.new.crushyinput(:title, {:input_value=>"It's my life"}).should.match(/value="It's my life"/)
end

should 'escape html by default on text fields' do
Haiku.new.crushyinput(:title, {:input_value=>"<ScRipT >alert('test');</ScRipT >"}).should.match(/&lt;ScRipT &gt;alert\('test'\);&lt;\/ScRipT &gt;/)
Haiku.new.crushyinput(:body, {:input_value=>"<ScRipT >alert('test');</ScRipT >"}).should.match(/&lt;ScRipT &gt;alert\('test'\);&lt;\/ScRipT &gt;/)
Expand Down Expand Up @@ -316,12 +320,12 @@ class WithAccronymYMCAName < ::Sequel::Model; end

should 'format date/time/datetime correctly' do
TestDateTime.new.db_schema[:meeting][:type].should== :time # Check that the correct type is used for following tests (see README)
TestDateTime.new.crushyinput(:birth).should.match(/value=''/)
TestDateTime.new.crushyinput(:birth,{:input_value=>::Time.now}).should.match(/value='\d{4}-\d{1,2}-\d{1,2}'/)
TestDateTime.new.crushyinput(:meeting).should.match(/value=''/)
TestDateTime.new.crushyinput(:meeting,{:input_value=>::Time.now}).should.match(/value='\d{1,2}:\d{1,2}:\d{1,2}'/)
TestDateTime.new.crushyinput(:when).should.match(/value=''/)
TestDateTime.new.crushyinput(:when,{:input_value=>::Time.now}).should.match(/value='\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}'/)
TestDateTime.new.crushyinput(:birth).should.match(/value=""/)
TestDateTime.new.crushyinput(:birth,{:input_value=>::Time.now}).should.match(/value="\d{4}-\d{1,2}-\d{1,2}"/)
TestDateTime.new.crushyinput(:meeting).should.match(/value=""/)
TestDateTime.new.crushyinput(:meeting,{:input_value=>::Time.now}).should.match(/value="\d{1,2}:\d{1,2}:\d{1,2}"/)
TestDateTime.new.crushyinput(:when).should.match(/value=""/)
TestDateTime.new.crushyinput(:when,{:input_value=>::Time.now}).should.match(/value="\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}"/)
end

should 'add format instructions for date/time/datetime after :required bit' do
Expand Down

0 comments on commit 4d95cfc

Please sign in to comment.