Ticket #99 (closed defect: fixed)

Opened 2 years ago

Last modified 14 months ago

Camping.qsp is failing on malformed query

Reported by: zimbatm Owned by: why
Priority: minor Milestone:
Component: bin/camping Version: 1.5
Keywords: Cc:

Description

If you have :

/?&x=y

You get :

#<NoMethodError: private method `split' called for nil:NilClass>
"(eval):41:in `qsp'"
"/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `inject'",
"(eval):40:in `qsp'",
"(eval):15:in `initialize'"
...

Change History

Changed 14 months ago by archengule

The part between the '?' and the '&' (nothing) can just be discarded, right? So, the following should work.

Index: camping-unabridged.rb
===================================================================
--- camping-unabridged.rb       (revision 221)
+++ camping-unabridged.rb       (working copy)
@@ -640,7 +640,8 @@
         m = proc {|_,o,n|o.u(n,&m)rescue([*o]<<n)}
         q.to_s.
             split(/[#{d}]+ */n).
-            inject((b,z=z,H[])[0]) { |h,p| k, v=un(p).split('=',2)
+            inject((b,z=z,H[])[0]) { |h,p| next h if p==''
+               k, v=un(p).split('=',2)
                 h.u(k.split(/[\]\[]+/).reverse.
                     inject(y||v) { |x,i| H[i,x] },&m)
             }

Changed 14 months ago by archengule

Actually, this is smaller

Index: camping-unabridged.rb
===================================================================
--- camping-unabridged.rb       (revision 223)
+++ camping-unabridged.rb       (working copy)
@@ -619,8 +619,8 @@
     #
     def qsp(q, d='&;', y=nil, z=H[])
         m = proc {|_,o,n|o.u(n,&m)rescue([*o]<<n)}
-        q.to_s.
-            split(/[#{d}]+ */n).
+        (q.to_s.
+            split(/[#{d}]+ */n)-['']).
             inject((b,z=z,H[])[0]) { |h,p| k, v=un(p).split('=',2)
                 h.u(k.split(/[\]\[]+/).reverse.
                     inject(y||v) { |x,i| H[i,x] },&m)

Changed 14 months ago by archengule

  • summary changed from Camping.qsp is failing on malformed query to [PATCH] Camping.qsp is failing on malformed query

With accompanying for camping.rb:

Index: camping.rb
===================================================================
--- camping.rb  (revision 223)
+++ camping.rb  (working copy)
@@ -39,8 +39,8 @@
 gsub(/Camping/,m.to_s),TOPLEVEL_BINDING;end;def escape s;s.to_s.gsub(
 /[^ \w.-]+/n){'%'+($&.unpack('H2'*$&.size)*'%').upcase}.tr(' ','+')end;def un s
 s.tr('+',' ').gsub(/%([\da-f]{2})/in){[$1].pack('H*')}end;def qsp q,d='&;',y=
-nil,z=H[];m=proc{|_,o,n|o.u(n,&m)rescue([*o]<<n)};q.to_s.split(/[#{d}]+ */n).
-inject((b,z=z,H[])[0]){|h,p|k,v=un(p).split('=',2);h.u k.split(/[\]\[]+/).
+nil,z=H[];m=proc{|_,o,n|o.u(n,&m)rescue([*o]<<n)};(q.to_s.split(/[#{d}]+ */n)-
+['']).inject((b,z=z,H[])[0]){|h,p|k,v=un(p).split('=',2);h.u k.split(/[\]\[]+/).
 reverse.inject(y||v){|x,i|H[i,x]},&m}end;def kp s;c=qsp(s,';,')end;def
 run r=$stdin,e=ENV;X.M;k,a=X.D un("/#{e['PATH_INFO']}".gsub(/\/+/,'/'));k.new(
 r,e,(m=e['REQUEST_METHOD']||"GET")).Y.service(*a);rescue=>x;X::ServerError.new(

Changed 14 months ago by archengule

  • summary changed from [PATCH] Camping.qsp is failing on malformed query to Camping.qsp is failing on malformed query

Whoops didn't mean to do that.

Changed 14 months ago by zimbatm

  • status changed from new to closed
  • resolution set to fixed

Thanks archengule, applied your patch to [229]

Note: See TracTickets for help on using tickets.