chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

& Character Trips up Save of Account #18

Closed frugardc closed 13 years ago

frugardc commented 13 years ago

Removing the & allows the save to happen.

irb(main):086:0> a = SugarCRM::Account.new

irb(main):087:0> a.name = "COHEN, WEISS & SIMON LLP"

=> "COHEN, WEISS & SIMON LLP"

irb(main):088:0> a.save

=> false

irb(main):089:0> a.errors

=> #<Set: {}>

irb(main):090:0> a.name = "COHEN, WEISS SIMON LLP"

=> "COHEN, WEISS SIMON LLP"

irb(main):091:0> a.save

=> true

irb(main):092:0>

chicks commented 13 years ago

Thanks for the bug! Will take a look tonight.

davidsulc commented 13 years ago

This seems to be a SugarCRM bug:

account = SugarCRM::Account.first
SugarCRM.connection.set_entry('Accounts', :id => account.id, :name => 'A & B')

fails with invalid request. However, the JSON name-value hash that is passed in Connection#set_entry is "name": "A & B", which is valid JSON (according to jsonlint.com)...

chicks commented 13 years ago

Yeah, this looks like a SugarCRM product bug. I'll see about opening a case tomorrow

chicks commented 13 years ago

I think this is an issue with the way I'm posting the JSON. If the total request length is < 3900 bytes, I send a "GET" request. When I send a GET, the JSON is encoded into the URL path, and since "&" symbols are used for joining URL parameters, it skips that symbol.

I'll look into pushing a fix today.

davidsulc commented 13 years ago

Now that you mention it, this explanation makes a lot of sense. SugarCRM wouldn't actually receive valid JSON, hence the error...

chicks commented 13 years ago

FYI, I've fixed this in my current checkout but I won't get around to merging the changes into head until I finish our next feature - Lazy Loaded Collections. Should be done later this week.

chicks commented 13 years ago

I fixed this and added tests for it. Please confirm and close!

davidsulc commented 13 years ago

Confirmed: can create account with name containing '&' and search for account with :conditions => {:name => "LIKE '%&%'"}

frugardc commented 13 years ago

Just updated to version 0.9.9. Works now. Thanks!