Permalink
Browse files

Fix issue where thousands separator was being applied to HTML entities

Fixes #272
  • Loading branch information...
1 parent a728353 commit 4edd4dd43704a30aa6b68edd4efc9f51348ab3bc @radar radar committed Apr 17, 2013
Showing with 16 additions and 10 deletions.
  1. +10 −10 lib/money/money/formatting.rb
  2. +6 −0 spec/money/formatting_spec.rb
@@ -214,6 +214,16 @@ def format(*rules)
formatted = "#{self.to_s.to_i}"
end
+ thousands_separator_value = thousands_separator
+ # Determine thousands_separator
+ if rules.has_key?(:thousands_separator)
+ thousands_separator_value = rules[:thousands_separator] || ''
+ end
+
+ # Apply thousands_separator
+ formatted.gsub!(regexp_format(formatted, rules, decimal_mark, symbol_value),
+ "\\1#{thousands_separator_value}")
+
symbol_position =
if rules.has_key?(:symbol_position)
rules[:symbol_position]
@@ -244,16 +254,6 @@ def format(*rules)
formatted.sub!(decimal_mark, rules[:decimal_mark])
end
- thousands_separator_value = thousands_separator
- # Determine thousands_separator
- if rules.has_key?(:thousands_separator)
- thousands_separator_value = rules[:thousands_separator] || ''
- end
-
- # Apply thousands_separator
- formatted.gsub!(regexp_format(formatted, rules, decimal_mark, symbol_value),
- "\\1#{thousands_separator_value}")
-
if rules[:with_currency]
formatted << " "
formatted << '<span class="currency">' if rules[:html]
@@ -171,6 +171,12 @@
Money.new(100000000, "USD").format(no_cents: true).should == "$1,000,000"
Money.new(100000000, "RUB").format(no_cents: true).should == "1.000.000 р."
end
+
+ it "doesn't incorrectly format HTML" do
+ money = ::Money.new(1999, "RUB")
+ output = money.format(:html => true, :no_cents => true)
+ output.should == "19 &#x0440;&#x0443;&#x0431;"
+ end
end
describe ":no_cents_if_whole option" do

0 comments on commit 4edd4dd

Please sign in to comment.