lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Luiz Henrique de Figueiredo once stated:
> >           query = "q=foo%20bar&lang=en",
> 
> Shouldn't query be a table?
> 
> query = { q = "foo bar", lang = "en" }
> 
> Or are there helper functions for that?

  It used to be decoded into a table, but there were issues doing that
related to CGI scripts (as defined in RFC-3875) where the following is
legal:

	http://example.com/search?look+for+this

(RFC-3875, section 4.4).  If I parsed that into a table, it would look
something like:

	q = { ['look+for+this'] = true }

  Faced with that reality [1], I decided not to decode the query string,
instead leaving that for the user of the library.  I do have some helper
code for URLs [3], but not as a standalone module yet.  I'm still debating
about where (as in namespace wise) to put them.  I don't want to add them to
org.conman.parsers.url since each module there [4] returns an LPEG
expression, which allows for [5]:

	url = require "org.conman.parsers.url.data"   -- data: is special
	    + require "org.conman.parsers.url.gopher" -- gopher: is annoying
	    + require "org.conman.parsers.url.siptel" -- phone numbers
	    + require "org.conman.parsres.url.tag"    -- tag: is also special
            + require "org.conman.parsers.url"        -- generic URI parsing

  I don't automatically include the modules for data:, gopher:, sip:, tel:
(siptel supports both in one module because of so much overlap between the
two) and tag: because they're rather specific in nature and don't quite
follow the normal URI scheme (although the generic parser can parse them).

  One thing I am working in is taking a decoded URL (which is a table) and
convert it into a string.  The only issue there are the other specific URL
types like data: and gopher:, which due their constructions, have different
fields than a generic URL, and how to include specific code when required
(much like how I have specific parsers for them that can be included at
will).

  -spc (This was probably a longer answer than expected ... )

[1]	I was implementing CGI support for the new Gemini protocol [2]:

		https://github.com/spc476/GLV-1.12556

[2]	An overview of the protocol:

		https://portal.mozz.us/gemini/gemini.circumlunar.space/

[3]	As part of my Gemini sever:

		https://github.com/spc476/GLV-1.12556/blob/master/Lua/GLV-1/url-util.lua

[4]	With one exception that I recently added.  I still may change my
	mind on that one, as it returns a table.

[5]	gopher and siptel are available via LuaRocks.  data and tag are
	not currently.