golgote / neturl Goto Github PK
View Code? Open in Web Editor NEWURL and Query string parser, builder, normalizer for Lua
License: MIT License
URL and Query string parser, builder, normalizer for Lua
License: MIT License
Add a configuration parameter to set the maximum number of parameters allowed in the query string
Url could use dot or nothing to specify sub level query string parameters, this should be possible.
When building URLs, it would be useful to be able to encode individual path segments, so that they can contain reserved characters such as /
.
For example, suppose I have a variable that contains the name of a band. I should be able to build up a URL that contains the name of the band as one of the path segments, e.g.
Band Name | URL |
---|---|
Pink Floyd | http://example.com/bands/Pink%20Floyd |
AC/DC | http://example.com/bands/AC%2FDC |
I think this is just a case of exposing the encodeSegment
function, which would mean I could write:
path = '/' .. url.encodeSegment('band') .. '/' .. url.encodeSegment('AC/DC')
Allow use of ; or & or whatever to separate query string parameters. This should be set in the parser or builder configuration.
I am trying to migrate from another URL parser to this library. There are differences between that and this library with respect to the host-related values (specifically inclusion vs. exclusion of :<port>
in the value). It would be super convenient to have each property and its exact semantics documented exhaustively at hand, instead of being referred to an RFC and having to wade through standardese.
Does neturl comply with RFC 3986?
Where can I find a complete API reference for this library, as opposed to the short readme that only touches a few APIs?
UX report: after I studied everything about this library that can be found online, getting my head around how to use this library to manipulate query strings still involved WAY too much trial and error.
Since the number of parameters in the query string can be high, it would be a good idea to parse them on demand (jit).
Some sites use setting multiple values for same
For example, query on russian job search site:
As you see it containts multiple values for one name:
schedule=fullDay&schedule=flexible&schedule=remote
local net_url = require 'thirdparty_libs.neturl_mod'
local u = net_url.parse [[https://hh.ru/search/vacancy?text=lua&salary=¤cy_code=RUR&experience=doesNotMatter&employment=full&employment=part&employment=project&schedule=fullDay&schedule=flexible&schedule=remote&order_by=relevance&search_period=&items_on_page=20&no_magic=true]]
print(u.query.schedule)
-- "fullDay"
As you see values other then the fiest are lost.
I propose ability to parse multiple values for one argument as
net_url.allow_args_names_repetition = true
local u = net_url.parse [[https://hh.ru/search/vacancy?text=lua&salary=¤cy_code=RUR&experience=doesNotMatter&employment=full&employment=part&employment=project&schedule=fullDay&schedule=flexible&schedule=remote&order_by=relevance&search_period=&items_on_page=20&no_magic=true]]
print(u.query.schedule)
-- "fullDay|flexible|remote"
When parsing a URL, this library strips the encoding from the path. But the encoding is not present when converting the URL back into a string:
th> u=url.parse("https://google.com/Link%20with%20a%20space%20in%20it/")
th> u
https://google.com/Link with a space in it/
th> {u:build()}
{
1 : "https://google.com/Link with a space in it/"
}
The resulting URL should never have a space character in it.
Other characters are not escaped properly either, e.g. https://google.com/a%2fb%2fc
resolves to https://google.com/a/b/c
, which could lead to some fun security issues...
Is this the right way to convert URLs back to strings? This seems like a pretty fundamental bug.
OpenResty Debian docker images now ship with OPM instead of LuaRocks. Would you consider publishing to OPM in addition moving forward?
> url = require("net.url")
> res = url.parse("http:// spacehost.com")
> = res.scheme
http
> = res.host
spacehost.com
>
In this case, the res.host
should be nil
right?
Hello,
can you please add a license to this?
Thank you!
r.
In order to parse TLD like .co.uk this library should match from the TLDs listed here: http://publicsuffix.org
url = http://example.com//a/b/c
neturl.parse(url):normalize()
Expected outcome
-- url.host = example.com
-- url.path = /a/b/c
Actual outcome
-- url.host = a
-- url.path = /b/c
Receive this error after importing and calling parseQuery
.
attempt to call method 'gmatch' (a nil value)
my knowledge of lua is limited and hopefully this is simple
Try the tests found here :
https://raw.github.com/postrank-labs/postrank-uri/master/spec/postrank-uri_spec.rb
Not the ones that remove query params...
Add a parameter to configure the maximum number of nested levels in the query string parameters. PHP has this set to 64 by default IIRC.
I started to work on these fixes. RFC 3986 recommends that spaces are all encoded as %20 and plus sign as %2B to avoid confusion. Other special characters can be left alone or encoded depending on the application (ex: ; = : ). I will add a list of reserved characters and make it configurable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.