diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb
index <HASH>..<HASH> 100644
--- a/lib/addressable/uri.rb
+++ b/lib/addressable/uri.rb
@@ -1725,7 +1725,7 @@ module Addressable
     #
     # @param [String, #to_str] new_query The new query component.
     def query=(new_query)
-      @query = new_query.to_str
+      @query = new_query ? new_query.to_str : nil
 
       # Reset dependant values
       @normalized_query = nil
diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb
index <HASH>..<HASH> 100644
--- a/spec/addressable/uri_spec.rb
+++ b/spec/addressable/uri_spec.rb
@@ -1876,6 +1876,10 @@ describe Addressable::URI, " when parsed from " +
     @uri.query.should == "newquery=x"
     @uri.to_s.should ==
       "http://user:pass@example.com/path/to/resource?newquery=x#fragment"
+    @uri.query = nil
+    @uri.query.should == nil
+    @uri.to_s.should ==
+      "http://user:pass@example.com/path/to/resource#fragment"
   end
 
   it "should have the correct query string after hash assignment" do
Fixed issue with assigning nil to queries spotted by Johan Friis.