diff --git a/lib/active_shipping/shipping/carriers/usps.rb b/lib/active_shipping/shipping/carriers/usps.rb index 12f99a123..0aa6811c3 100644 --- a/lib/active_shipping/shipping/carriers/usps.rb +++ b/lib/active_shipping/shipping/carriers/usps.rb @@ -315,7 +315,10 @@ def rates_from_response_node(response_node, packages) package_node.each_element(service_node) do |service_response_node| service_name = service_response_node.get_text(service_name_node).to_s - + + # workaround for USPS messing up and including unescaped html in their rate names since Jan 2, 2011 + service_name.gsub!(/&lt;sup&gt;&amp;reg;&lt;\/sup&gt;/, '') + # aggregate specific package rates into a service-centric RateEstimate # first package with a given service name will initialize these; # later packages with same service will add to them diff --git a/test/fixtures/xml/usps/2011_rates_response.xml b/test/fixtures/xml/usps/2011_rates_response.xml new file mode 100644 index 000000000..29a6eabcd --- /dev/null +++ b/test/fixtures/xml/usps/2011_rates_response.xml @@ -0,0 +1,101 @@ + + + + 83843 + 70001 + 0 + 32.0 + + REGULAR + FALSE + 8 + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; + 34.70 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Hold For Pickup + 34.70 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Sunday/Holiday Delivery + 47.20 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Flat Rate Envelope + 18.30 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Flat Rate Envelope Hold For Pickup + 18.30 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Sunday/Holiday Delivery Flat Rate Envelope + 30.80 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Legal Flat Rate Envelope + 18.30 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Legal Flat Rate Envelope Hold For Pickup + 18.30 + + + Express Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Sunday/Holiday Delivery Legal Flat Rate Envelope + 30.80 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; + 10.20 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Large Flat Rate Box + 14.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Medium Flat Rate Box + 10.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Small Flat Rate Box + 5.20 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Flat Rate Envelope + 4.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Legal Flat Rate Envelope + 4.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Padded Flat Rate Envelope + 4.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Gift Card Flat Rate Envelope + 4.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Small Flat Rate Envelope + 4.95 + + + Priority Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Window Flat Rate Envelope + 4.95 + + + Parcel Post&lt;sup&gt;&amp;reg;&lt;/sup&gt; + 8.09 + + + Media Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; + 2.77 + + + Library Mail + 2.63 + + + diff --git a/test/unit/carriers/usps_test.rb b/test/unit/carriers/usps_test.rb index 3057482ae..fc8b17676 100644 --- a/test/unit/carriers/usps_test.rb +++ b/test/unit/carriers/usps_test.rb @@ -136,6 +136,42 @@ def test_maximum_weight assert Package.new((70 * 16) - 0.01, [5,5,5], :units => :imperial).mass < @carrier.maximum_weight end + def test_updated_rate_name_format_with_unescaped_html + mock_response = xml_fixture('usps/2011_rates_response') + @carrier.expects(:commit).returns(mock_response) + rates_response = @carrier.find_rates( + @locations[:beverly_hills], + @locations[:ottawa], + @packages[:book], + :test => true + ) + rate_names = [ + 'USPS Express Mail', + 'USPS Express Mail Flat Rate Envelope', + 'USPS Express Mail Flat Rate Envelope Hold For Pickup', + 'USPS Express Mail Hold For Pickup', + 'USPS Express Mail Legal Flat Rate Envelope', + 'USPS Express Mail Legal Flat Rate Envelope Hold For Pickup', + 'USPS Express Mail Sunday/Holiday Delivery', + 'USPS Express Mail Sunday/Holiday Delivery Flat Rate Envelope', + 'USPS Express Mail Sunday/Holiday Delivery Legal Flat Rate Envelope', + 'USPS Library Mail', + 'USPS Media Mail', + 'USPS Parcel Post', + 'USPS Priority Mail', + 'USPS Priority Mail Flat Rate Envelope', + 'USPS Priority Mail Gift Card Flat Rate Envelope', + 'USPS Priority Mail Large Flat Rate Box', + 'USPS Priority Mail Legal Flat Rate Envelope', + 'USPS Priority Mail Medium Flat Rate Box', + 'USPS Priority Mail Padded Flat Rate Envelope', + 'USPS Priority Mail Small Flat Rate Box', + 'USPS Priority Mail Small Flat Rate Envelope', + 'USPS Priority Mail Window Flat Rate Envelope' + ] + assert_equal rate_names, rates_response.rates.collect(&:service_name).sort + end + private def build_service_node(options = {})