Commit 494f33d06cabc335c2bf9d63dfd555ed82cbaad0
- Date: Tue Apr 15 21:29:42 +0000 2008
- Committer: Sebastian Probst Eide (sebastian.probst.eide@gmail.com)
- Author: Sebastian Probst Eide (sebastian.probst.eide@gmail.com)
- Commit SHA1: 494f33d06cabc335c2bf9d63dfd555ed82cbaad0
- Tree SHA1: e43acf8647919f1df4e3cce6b4f814e869be17e5
Now the forceful change of encoding (to UTF-8) is only performed if the normal .to_json fails. Better and ster.
Commit diff
| |   |
| 698 | 698 | |
| 699 | 699 | parameters["belongs_to"] = @belongs_to if @couch_initial_load && @belongs_to |
| 700 | 700 | |
| 701 | | # In case the user wants to save some funky strings we have to decode |
| 702 | | # them first. |
| 703 | | CouchObject::Utils::decode_strings(parameters).to_json |
| 704 | | |
| 701 | begin |
| 702 | parameters.to_json |
| 703 | rescue JSON::GeneratorError |
| 704 | # All strings aren't encoded properly, so we have to force them into |
| 705 | # UTF-8. |
| 706 | # FIXME: The kconv library has some weird artefacts though where |
| 707 | # a lot of Norwegian (Scandianavian?) letters get turned into |
| 708 | # asian characters of some sort! |
| 709 | CouchObject::Utils::decode_strings(parameters).to_json |
| 710 | end |
| 711 | |
| 705 | 712 | end |
| 706 | 713 | |
| 707 | 714 | |
| toggle raw diff |
--- a/lib/couch_object/persistable.rb
+++ b/lib/couch_object/persistable.rb
@@ -698,10 +698,17 @@ module CouchObject
parameters["belongs_to"] = @belongs_to if @couch_initial_load && @belongs_to
- # In case the user wants to save some funky strings we have to decode
- # them first.
- CouchObject::Utils::decode_strings(parameters).to_json
-
+ begin
+ parameters.to_json
+ rescue JSON::GeneratorError
+ # All strings aren't encoded properly, so we have to force them into
+ # UTF-8.
+ # FIXME: The kconv library has some weird artefacts though where
+ # a lot of Norwegian (Scandianavian?) letters get turned into
+ # asian characters of some sort!
+ CouchObject::Utils::decode_strings(parameters).to_json
+ end
+
end
|