Skip to content

Commit d629894

Browse files
committedSep 3, 2024·
chore(*): release 1.1.0
### Summary #### Added - `url:decode` method - `ada.decode` function - `search:decode` method - `search:decode_all` method - `ada.search_encode` function - `ada.search.encode` function - `ada.search_decode` function - `ada.search.decode` function - `ada.search_decode_all` function - `ada.search.decode_all` function #### Changed - The `set_port` to not allow negative or positive inf or NaN #### Updated - The CI is now executed against Ada 2.9.1 Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
1 parent 343dce0 commit d629894

File tree

8 files changed

+614
-11
lines changed

8 files changed

+614
-11
lines changed
 

‎CHANGES.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22

33
All notable changes to `lua-resty-ada` will be documented in this file.
44

5+
## [1.1.0] - 2024-09-03
6+
### Added
7+
- `url:decode` method
8+
- `ada.decode` function
9+
- `ada.search_encode` function
10+
- `ada.search.encode` function
11+
- `search:decode` method
12+
- `search:decode_all` method
13+
- `ada.search_decode` function
14+
- `ada.search.decode` function
15+
- `ada.search_decode_all` function
16+
- `ada.search.decode_all` function
17+
### Changed
18+
- The `set_port` to not allow negative or positive inf or NaN
19+
### Updated
20+
- The CI is now executed against Ada 2.9.2
521

622
## [1.0.1] - 2024-08-20
723
### Removed
824
- The unnecessary `:is_valid` was removed (the URL is validated when parsed)
9-
1025
### Added
1126
- Explicitly free Ada URL object on invalid URLs
1227

‎docs/classes/search.html

+82-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ <h1>resty.ada</h1>
3434

3535
<h2>Contents</h2>
3636
<ul>
37+
<li><a href="#Decode_Methods">Decode Methods </a></li>
3738
<li><a href="#Has_Methods">Has Methods </a></li>
3839
<li><a href="#Get_Methods">Get Methods </a></li>
3940
<li><a href="#Set_Methods">Set Methods </a></li>
@@ -65,6 +66,17 @@ <h1>Class <code>search</code></h1>
6566
<p> See: <a href="https://url.spec.whatwg.org/#interface-urlsearchparams">https://url.spec.whatwg.org/#interface-urlsearchparams</a></p>
6667

6768

69+
<h2><a href="#Decode_Methods">Decode Methods </a></h2>
70+
<table class="function_list">
71+
<tr>
72+
<td class="name" nowrap><a href="#search:decode">search:decode ()</a></td>
73+
<td class="summary">Decodes search parameters and returns a Lua table of them.</td>
74+
</tr>
75+
<tr>
76+
<td class="name" nowrap><a href="#search:decode">search:decode ()</a></td>
77+
<td class="summary">Decodes all search parameters and returns a Lua table of them.</td>
78+
</tr>
79+
</table>
6880
<h2><a href="#Has_Methods">Has Methods </a></h2>
6981
<table class="function_list">
7082
<tr>
@@ -182,6 +194,75 @@ <h2><a href="#Iterate_Methods">Iterate Methods </a></h2>
182194
<br/>
183195

184196

197+
<h2 class="section-header "><a name="Decode_Methods"></a>Decode Methods </h2>
198+
199+
<dl class="function">
200+
<dt>
201+
<a name = "search:decode"></a>
202+
<strong>search:decode ()</strong>
203+
</dt>
204+
<dd>
205+
Decodes search parameters and returns a Lua table of them.</p>
206+
207+
<p> If same parameter appears multiple times, only the value of the
208+
first is returned.</p>
209+
210+
<p> An example return value:
211+
{
212+
key1 = &ldquo;value&rdquo;,
213+
key2 = &ldquo;value2&rdquo;,
214+
}
215+
216+
217+
218+
<h3>Returns:</h3>
219+
<ol>
220+
221+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
222+
a table of all search parameters (a string:string map).
223+
</ol>
224+
225+
226+
227+
<h3>Usage:</h3>
228+
<ul>
229+
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>).<span class="function-name">parse</span>(<span class="string">"a=b&amp;c=d&amp;e=f&amp;a=g"</span>)
230+
<span class="keyword">local</span> result = search:<span class="function-name">decode</span>()</pre>
231+
</ul>
232+
233+
</dd>
234+
<dt>
235+
<a name = "search:decode"></a>
236+
<strong>search:decode ()</strong>
237+
</dt>
238+
<dd>
239+
Decodes all search parameters and returns a Lua table of them.</p>
240+
241+
<p> An example return value:
242+
{
243+
key1 = { &ldquo;first&rdquo;, &ldquo;second&rdquo;, },
244+
key2 = { &ldquo;value&rdquo; },
245+
}
246+
247+
248+
249+
<h3>Returns:</h3>
250+
<ol>
251+
252+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
253+
a table of all search parameters (a string:table [array] map).
254+
</ol>
255+
256+
257+
258+
<h3>Usage:</h3>
259+
<ul>
260+
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>).<span class="function-name">parse</span>(<span class="string">"a=b&amp;a=c&amp;d=e"</span>)
261+
<span class="keyword">local</span> result = search:<span class="function-name">decode_all</span>()</pre>
262+
</ul>
263+
264+
</dd>
265+
</dl>
185266
<h2 class="section-header "><a name="Has_Methods"></a>Has Methods </h2>
186267

187268
<dl class="function">
@@ -922,7 +1003,7 @@ <h3>Usage:</h3>
9221003
</div> <!-- id="main" -->
9231004
<div id="about">
9241005
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
925-
<i style="float:right;">Last updated 2024-08-20 21:17:51 </i>
1006+
<i style="float:right;">Last updated 2024-09-03 15:49:45 </i>
9261007
</div> <!-- id="about" -->
9271008
</div> <!-- id="container" -->
9281009
</body>

‎docs/classes/url.html

+141-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ <h1>resty.ada</h1>
3434

3535
<h2>Contents</h2>
3636
<ul>
37+
<li><a href="#Decode_Methods">Decode Methods </a></li>
3738
<li><a href="#Has_Methods">Has Methods </a></li>
3839
<li><a href="#Get_Methods">Get Methods </a></li>
3940
<li><a href="#Set_Methods">Set Methods </a></li>
@@ -66,6 +67,13 @@ <h1>Class <code>url</code></h1>
6667
<p> See: <a href="https://url.spec.whatwg.org/#url-representation">https://url.spec.whatwg.org/#url-representation</a></p>
6768

6869

70+
<h2><a href="#Decode_Methods">Decode Methods </a></h2>
71+
<table class="function_list">
72+
<tr>
73+
<td class="name" nowrap><a href="#url:decode">url:decode ()</a></td>
74+
<td class="summary">Decodes URL and return its components in Lua table.</td>
75+
</tr>
76+
</table>
6977
<h2><a href="#Has_Methods">Has Methods </a></h2>
7078
<table class="function_list">
7179
<tr>
@@ -230,6 +238,14 @@ <h2><a href="#Search_Methods">Search Methods </a></h2>
230238
<td class="summary">Parses search from URL and returns an instance of Ada URL Search.</td>
231239
</tr>
232240
<tr>
241+
<td class="name" nowrap><a href="#url:search_decode">url:search_decode ()</a></td>
242+
<td class="summary">Decodes search parameters from URL and returns a Lua table of them.</td>
243+
</tr>
244+
<tr>
245+
<td class="name" nowrap><a href="#url:search_decode_all">url:search_decode_all (url)</a></td>
246+
<td class="summary">Decodes all search parameters from URL and returns a Lua table of them.</td>
247+
</tr>
248+
<tr>
233249
<td class="name" nowrap><a href="#url:search_has">url:search_has (key)</a></td>
234250
<td class="summary">Checks whether the url has a search with a key.</td>
235251
</tr>
@@ -327,6 +343,55 @@ <h2><a href="#Properties">Properties </a></h2>
327343
<br/>
328344

329345

346+
<h2 class="section-header "><a name="Decode_Methods"></a>Decode Methods </h2>
347+
348+
<dl class="function">
349+
<dt>
350+
<a name = "url:decode"></a>
351+
<strong>url:decode ()</strong>
352+
</dt>
353+
<dd>
354+
Decodes URL and return its components in Lua table.</p>
355+
356+
<p> Given a following URL:
357+
https://user:pass@example.com:1234/foo/bar?baz#quux</p>
358+
359+
<p> This function will return following table:
360+
{
361+
scheme_type = 2,
362+
protocol = &ldquo;https:&rdquo;,
363+
username = &ldquo;user&rdquo;,
364+
password = &ldquo;pass&rdquo;,
365+
origin = &ldquo;https://example.com:1234&rdquo;,
366+
host_type = 0,
367+
host = &ldquo;example.com:1234&rdquo;,
368+
hostname = &ldquo;example.com&rdquo;,
369+
port = 1234,
370+
pathname = &ldquo;/foo/bar&rdquo;,
371+
search = &ldquo;?baz&rdquo;,
372+
hash = &ldquo;#quux&rdquo;,
373+
}
374+
375+
376+
377+
<h3>Returns:</h3>
378+
<ol>
379+
380+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
381+
table of URL components
382+
</ol>
383+
384+
385+
386+
<h3>Usage:</h3>
387+
<ul>
388+
<pre class="example"><span class="keyword">local</span> url = <span class="global">require</span>(<span class="string">"resty.ada"</span>).<span class="function-name">parse</span>(
389+
<span class="string">"https://user:pass@host:1234/path?search#hash"</span>)
390+
<span class="keyword">local</span> res = url:<span class="function-name">decode</span>()</pre>
391+
</ul>
392+
393+
</dd>
394+
</dl>
330395
<h2 class="section-header "><a name="Has_Methods"></a>Has Methods </h2>
331396

332397
<dl class="function">
@@ -1235,6 +1300,8 @@ <h3>Usage:</h3>
12351300
<dd>
12361301
Sets port to the URL.</p>
12371302

1303+
<p> Note: inf, -inf and NaN are considered invalid and they raise an error.</p>
1304+
12381305
<p> See: <a href="https://url.spec.whatwg.org/#dom-url-port">https://url.spec.whatwg.org/#dom-url-port</a>
12391306

12401307

@@ -1253,7 +1320,7 @@ <h3>Returns:</h3>
12531320
self (except on errors <code>nil</code>)</li>
12541321
<li>
12551322
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
1256-
error message</li>
1323+
error message (e.g. when port is out of acceptable range)</li>
12571324
</ol>
12581325

12591326
<h3>Raises:</h3>
@@ -1491,6 +1558,78 @@ <h3>Usage:</h3>
14911558
<span class="keyword">local</span> search = url:<span class="function-name">search_parse</span>()</pre>
14921559
</ul>
14931560

1561+
</dd>
1562+
<dt>
1563+
<a name = "url:search_decode"></a>
1564+
<strong>url:search_decode ()</strong>
1565+
</dt>
1566+
<dd>
1567+
Decodes search parameters from URL and returns a Lua table of them.</p>
1568+
1569+
<p> If same parameter appears multiple times, only the value of the
1570+
first is returned.</p>
1571+
1572+
<p> An example return value:
1573+
{
1574+
key1 = &ldquo;value&rdquo;,
1575+
key2 = &ldquo;value2&rdquo;,
1576+
}
1577+
1578+
1579+
1580+
<h3>Returns:</h3>
1581+
<ol>
1582+
1583+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
1584+
a table of all search parameters (a string:string map).
1585+
</ol>
1586+
1587+
1588+
1589+
<h3>Usage:</h3>
1590+
<ul>
1591+
<pre class="example"><span class="keyword">local</span> url = <span class="global">require</span>(<span class="string">"resty.ada"</span>).<span class="function-name">parse</span>(<span class="string">"http://host/?a=b&amp;c=d&amp;e=f&amp;a=g"</span>)
1592+
<span class="keyword">local</span> result = url:<span class="function-name">search_decode</span>()</pre>
1593+
</ul>
1594+
1595+
</dd>
1596+
<dt>
1597+
<a name = "url:search_decode_all"></a>
1598+
<strong>url:search_decode_all (url)</strong>
1599+
</dt>
1600+
<dd>
1601+
Decodes all search parameters from URL and returns a Lua table of them.</p>
1602+
1603+
<p> An example return value:
1604+
{
1605+
key1 = { &ldquo;first&rdquo;, &ldquo;second&rdquo;, },
1606+
key2 = { &ldquo;value&rdquo; },
1607+
}
1608+
1609+
1610+
<h3>Parameters:</h3>
1611+
<ul>
1612+
<li><span class="parameter">url</span>
1613+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
1614+
url (with search) to parse
1615+
</li>
1616+
</ul>
1617+
1618+
<h3>Returns:</h3>
1619+
<ol>
1620+
1621+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
1622+
a table of all search parameters (a string:table [array] map).
1623+
</ol>
1624+
1625+
1626+
1627+
<h3>Usage:</h3>
1628+
<ul>
1629+
<pre class="example"><span class="keyword">local</span> url = <span class="global">require</span>(<span class="string">"resty.ada"</span>).<span class="function-name">parse</span>(<span class="string">"http://host/?a=b&amp;a=c&amp;d=e"</span>)
1630+
<span class="keyword">local</span> result = url:<span class="function-name">search_decode_all</span>()</pre>
1631+
</ul>
1632+
14941633
</dd>
14951634
<dt>
14961635
<a name = "url:search_has"></a>
@@ -2124,7 +2263,7 @@ <h2 class="section-header "><a name="Properties"></a>Properties </h2>
21242263
</div> <!-- id="main" -->
21252264
<div id="about">
21262265
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
2127-
<i style="float:right;">Last updated 2024-08-20 21:17:51 </i>
2266+
<i style="float:right;">Last updated 2024-09-03 15:49:45 </i>
21282267
</div> <!-- id="about" -->
21292268
</div> <!-- id="container" -->
21302269
</body>

‎docs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h2>Classes</h2>
7777
</div> <!-- id="main" -->
7878
<div id="about">
7979
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
80-
<i style="float:right;">Last updated 2024-08-20 21:17:51 </i>
80+
<i style="float:right;">Last updated 2024-09-03 15:49:45 </i>
8181
</div> <!-- id="about" -->
8282
</div> <!-- id="container" -->
8383
</body>

‎docs/modules/resty.ada.html

+210-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ <h2>Contents</h2>
3737
<li><a href="#Constructors">Constructors </a></li>
3838
<li><a href="#Convert_Functions">Convert Functions </a></li>
3939
<li><a href="#Validate_Functions">Validate Functions </a></li>
40+
<li><a href="#Decode_Functions">Decode Functions </a></li>
4041
<li><a href="#Has_Functions">Has Functions </a></li>
4142
<li><a href="#Get_Functions">Get Functions </a></li>
4243
<li><a href="#Set_Functions">Set Functions </a></li>
@@ -100,6 +101,13 @@ <h2><a href="#Validate_Functions">Validate Functions </a></h2>
100101
<td class="summary">Checks whether the URL can be parsed with a base URL.</td>
101102
</tr>
102103
</table>
104+
<h2><a href="#Decode_Functions">Decode Functions </a></h2>
105+
<table class="function_list">
106+
<tr>
107+
<td class="name" nowrap><a href="#decode">decode ()</a></td>
108+
<td class="summary">Decodes URL and return its components in Lua table.</td>
109+
</tr>
110+
</table>
103111
<h2><a href="#Has_Functions">Has Functions </a></h2>
104112
<table class="function_list">
105113
<tr>
@@ -260,6 +268,18 @@ <h2><a href="#Search_Functions">Search Functions </a></h2>
260268
<td class="summary">Parses search from URL and returns an instance of Ada URL Search.</td>
261269
</tr>
262270
<tr>
271+
<td class="name" nowrap><a href="#search_encode">search_encode (url)</a></td>
272+
<td class="summary">Encodes search parameters from URL and returns an query string.</td>
273+
</tr>
274+
<tr>
275+
<td class="name" nowrap><a href="#search_decode">search_decode (url)</a></td>
276+
<td class="summary">Decodes search parameters from URL and returns a Lua table of them.</td>
277+
</tr>
278+
<tr>
279+
<td class="name" nowrap><a href="#search_decode_all">search_decode_all (url)</a></td>
280+
<td class="summary">Decodes all search parameters and returns a Lua table of them.</td>
281+
</tr>
282+
<tr>
263283
<td class="name" nowrap><a href="#search_has">search_has (url, key)</a></td>
264284
<td class="summary">Checks whether the url has a search with a key.</td>
265285
</tr>
@@ -642,6 +662,63 @@ <h3>Usage:</h3>
642662
<span class="string">"https://user:pass@host:1234"</span>)</pre>
643663
</ul>
644664

665+
</dd>
666+
</dl>
667+
<h2 class="section-header "><a name="Decode_Functions"></a>Decode Functions </h2>
668+
669+
<dl class="function">
670+
<dt>
671+
<a name = "decode"></a>
672+
<strong>decode ()</strong>
673+
</dt>
674+
<dd>
675+
Decodes URL and return its components in Lua table.</p>
676+
677+
<p> Given a following URL:
678+
https://user:pass@example.com:1234/foo/bar?baz#quux</p>
679+
680+
<p> This function will return the following table:</p>
681+
682+
<pre><code>{
683+
origin = "https://example.com:1234",
684+
scheme_type = 2,
685+
protocol = "https:",
686+
username = "user",
687+
password = "pass",
688+
host_type = 0,
689+
host = "example.com:1234",
690+
hostname = "example.com",
691+
port = 1234,
692+
pathname = "/foo/bar",
693+
search = "?baz",
694+
hash = "#quux",
695+
}
696+
</code></pre>
697+
698+
<p> The missing ones will be returned as empty string <code>&quot;&quot;</code> (rather than <code>nil</code>).
699+
700+
701+
702+
<h3>Returns:</h3>
703+
<ol>
704+
<li>
705+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <span class="type">nil</span></span>
706+
table of URL components (except on errors <code>nil</code>)</li>
707+
<li>
708+
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
709+
error message</li>
710+
</ol>
711+
712+
<h3>Raises:</h3>
713+
error when url is not a string
714+
715+
716+
<h3>Usage:</h3>
717+
<ul>
718+
<pre class="example"><span class="keyword">local</span> ada = <span class="global">require</span>(<span class="string">"resty.ada"</span>)
719+
<span class="keyword">local</span> res = ada.<span class="function-name">decode</span>(<span class="string">"https://user:pass@host:1234/path?search#hash"</span>)</pre>
720+
</ul>
721+
645722
</dd>
646723
</dl>
647724
<h2 class="section-header "><a name="Has_Functions"></a>Has Functions </h2>
@@ -2306,7 +2383,138 @@ <h3>Raises:</h3>
23062383

23072384
<h3>Usage:</h3>
23082385
<ul>
2309-
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>).<span class="function-name">parse</span>(<span class="string">"a=b&amp;c=d&amp;e=f"</span>)</pre>
2386+
<pre class="example"><span class="keyword">local</span> ada = <span class="global">require</span>(<span class="string">"resty.ada"</span>)
2387+
<span class="keyword">local</span> res = ada.<span class="function-name">search_parse</span>(<span class="string">"http://host/?a=b&amp;c=d&amp;e=f&amp;a=g"</span>)</pre>
2388+
</ul>
2389+
2390+
</dd>
2391+
<dt>
2392+
<a name = "search_encode"></a>
2393+
<strong>search_encode (url)</strong>
2394+
</dt>
2395+
<dd>
2396+
Encodes search parameters from URL and returns an query string.
2397+
2398+
2399+
<h3>Parameters:</h3>
2400+
<ul>
2401+
<li><span class="parameter">url</span>
2402+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2403+
url (with search) to parse
2404+
</li>
2405+
</ul>
2406+
2407+
<h3>Returns:</h3>
2408+
<ol>
2409+
2410+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2411+
encoded query string
2412+
</ol>
2413+
2414+
<h3>Raises:</h3>
2415+
error when url is not a string
2416+
2417+
2418+
<h3>Usage:</h3>
2419+
<ul>
2420+
<pre class="example"><span class="keyword">local</span> ada = <span class="global">require</span>(<span class="string">"resty.ada"</span>)
2421+
<span class="keyword">local</span> res = ada.<span class="function-name">search_encode</span>(<span class="string">"http://host/?a=b&amp;c=d&amp;e=f&amp;a=g"</span>)</pre>
2422+
</ul>
2423+
2424+
</dd>
2425+
<dt>
2426+
<a name = "search_decode"></a>
2427+
<strong>search_decode (url)</strong>
2428+
</dt>
2429+
<dd>
2430+
Decodes search parameters from URL and returns a Lua table of them.</p>
2431+
2432+
<p> If same parameter appears multiple times, only the value of the
2433+
first is returned.</p>
2434+
2435+
<p> Given the following URL:
2436+
&ldquo;http://host/?a=b&amp;c=d&amp;e=f&amp;a=g&rdquo;</p>
2437+
2438+
<p> The following table is returned:
2439+
{
2440+
a = &ldquo;b&rdquo;,
2441+
c = &ldquo;d&rdquo;,
2442+
e = &ldquo;f&rdquo;,
2443+
}
2444+
2445+
2446+
<h3>Parameters:</h3>
2447+
<ul>
2448+
<li><span class="parameter">url</span>
2449+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2450+
url (with search) to parse
2451+
</li>
2452+
</ul>
2453+
2454+
<h3>Returns:</h3>
2455+
<ol>
2456+
<li>
2457+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <span class="type">nil</span></span>
2458+
a table of all search parameters (a string:string map).</li>
2459+
<li>
2460+
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2461+
error message</li>
2462+
</ol>
2463+
2464+
<h3>Raises:</h3>
2465+
error when url is not a string
2466+
2467+
2468+
<h3>Usage:</h3>
2469+
<ul>
2470+
<pre class="example"><span class="keyword">local</span> ada = <span class="global">require</span>(<span class="string">"resty.ada"</span>)
2471+
<span class="keyword">local</span> res = ada.<span class="function-name">search_decode</span>(<span class="string">"http://host/?a=b&amp;c=d&amp;e=f&amp;a=g"</span>)</pre>
2472+
</ul>
2473+
2474+
</dd>
2475+
<dt>
2476+
<a name = "search_decode_all"></a>
2477+
<strong>search_decode_all (url)</strong>
2478+
</dt>
2479+
<dd>
2480+
Decodes all search parameters and returns a Lua table of them.</p>
2481+
2482+
<p> Given the following URL:
2483+
&ldquo;http://host/?a=b&amp;a=c&amp;d=e&rdquo;"</p>
2484+
2485+
<p> The following table is returned:
2486+
{
2487+
a = { &ldquo;b&rdquo;, &ldquo;c&rdquo; },
2488+
d = { &ldquo;e&rdquo; },
2489+
}
2490+
2491+
2492+
<h3>Parameters:</h3>
2493+
<ul>
2494+
<li><span class="parameter">url</span>
2495+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2496+
url (with search) to parse
2497+
</li>
2498+
</ul>
2499+
2500+
<h3>Returns:</h3>
2501+
<ol>
2502+
<li>
2503+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <span class="type">nil</span></span>
2504+
a table of all search parameters (a string:table [array] map).</li>
2505+
<li>
2506+
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2507+
error message</li>
2508+
</ol>
2509+
2510+
<h3>Raises:</h3>
2511+
error when url is not a string
2512+
2513+
2514+
<h3>Usage:</h3>
2515+
<ul>
2516+
<pre class="example"><span class="keyword">local</span> ada = <span class="global">require</span>(<span class="string">"resty.ada"</span>)
2517+
<span class="keyword">local</span> res = ada.<span class="function-name">search_decode_all</span>(<span class="string">"http://host/?a=b&amp;a=c&amp;d=e"</span>)</pre>
23102518
</ul>
23112519

23122520
</dd>
@@ -2976,7 +3184,7 @@ <h3>Usage:</h3>
29763184
</div> <!-- id="main" -->
29773185
<div id="about">
29783186
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
2979-
<i style="float:right;">Last updated 2024-08-20 21:17:51 </i>
3187+
<i style="float:right;">Last updated 2024-09-03 15:49:45 </i>
29803188
</div> <!-- id="about" -->
29813189
</div> <!-- id="container" -->
29823190
</body>

‎docs/modules/resty.ada.search.html

+161-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h2>Contents</h2>
3838
<li><a href="#Has_Functions">Has Functions </a></li>
3939
<li><a href="#Get_Functions">Get Functions </a></li>
4040
<li><a href="#Set_Functions">Set Functions </a></li>
41+
<li><a href="#Encode_and_Decode_Functions">Encode and Decode Functions </a></li>
4142
<li><a href="#Remove_Functions">Remove Functions </a></li>
4243
<li><a href="#Iterate_Functions">Iterate Functions </a></li>
4344
<li><a href="#Other_Functions">Other Functions </a></li>
@@ -104,6 +105,21 @@ <h2><a href="#Set_Functions">Set Functions </a></h2>
104105
<td class="summary">Append value to the the search parameter.</td>
105106
</tr>
106107
</table>
108+
<h2><a href="#Encode_and_Decode_Functions">Encode and Decode Functions </a></h2>
109+
<table class="function_list">
110+
<tr>
111+
<td class="name" nowrap><a href="#encode">encode (params)</a></td>
112+
<td class="summary">Encodes search parameters and returns an query string.</td>
113+
</tr>
114+
<tr>
115+
<td class="name" nowrap><a href="#decode">decode (search)</a></td>
116+
<td class="summary">Decodes search parameters and returns a Lua table of them.</td>
117+
</tr>
118+
<tr>
119+
<td class="name" nowrap><a href="#decode_all">decode_all (search)</a></td>
120+
<td class="summary">Decodes all search parameters and returns a Lua table of them.</td>
121+
</tr>
122+
</table>
107123
<h2><a href="#Remove_Functions">Remove Functions </a></h2>
108124
<table class="function_list">
109125
<tr>
@@ -455,6 +471,150 @@ <h3>Usage:</h3>
455471
<span class="keyword">local</span> result = search.<span class="function-name">append</span>(<span class="string">"a=b&amp;c=d&amp;e=f"</span>, <span class="string">"a"</span>, <span class="string">"g"</span>)</pre>
456472
</ul>
457473

474+
</dd>
475+
</dl>
476+
<h2 class="section-header "><a name="Encode_and_Decode_Functions"></a>Encode and Decode Functions </h2>
477+
478+
<dl class="function">
479+
<dt>
480+
<a name = "encode"></a>
481+
<strong>encode (params)</strong>
482+
</dt>
483+
<dd>
484+
Encodes search parameters and returns an query string.</p>
485+
486+
<ul>
487+
<li>only <a href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> keys are allowed.</li>
488+
<li>only <a href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <code>boolean</code> and <code>number</code> values are allowed or an array of them</li>
489+
<li><code>false</code> value is treated as missing (same as <code>nil</code>)</li>
490+
<li><code>true</code> returns <code>&quot;&quot;</code> (empty string)</li>
491+
<li>negative and positive <code>inf</code> and <code>NaN</code> are not allowed as numbers in values</li>
492+
</ul>
493+
494+
495+
<p> When passing a table the keys will be sorted and with string the given order
496+
is preserved.
497+
498+
499+
<h3>Parameters:</h3>
500+
<ul>
501+
<li><span class="parameter">params</span>
502+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
503+
search parameters to encode (either a <a href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <a href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a>)
504+
</li>
505+
</ul>
506+
507+
<h3>Returns:</h3>
508+
<ol>
509+
510+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
511+
encoded query string
512+
</ol>
513+
514+
<h3>Raises:</h3>
515+
error when search or key is not a table or string, or when the rules above are not followed
516+
517+
518+
<h3>Usage:</h3>
519+
<ul>
520+
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>)
521+
<span class="keyword">local</span> result = search.<span class="function-name">encode</span>({
522+
g = <span class="string">"h"</span>,
523+
a = { <span class="string">"f"</span>, <span class="string">"b"</span>, },
524+
c = <span class="string">"d"</span>,
525+
})</pre>
526+
</ul>
527+
528+
</dd>
529+
<dt>
530+
<a name = "decode"></a>
531+
<strong>decode (search)</strong>
532+
</dt>
533+
<dd>
534+
Decodes search parameters and returns a Lua table of them.</p>
535+
536+
<p> If same parameter appears multiple times, only the value of the
537+
first is returned.</p>
538+
539+
<p> Given the following query string:
540+
&ldquo;a=b&amp;c=d&amp;e=f&amp;a=g&rdquo;</p>
541+
542+
<p> The following table is returned:
543+
{
544+
a = &ldquo;b&rdquo;,
545+
c = &ldquo;d&rdquo;,
546+
e = &ldquo;f&rdquo;,
547+
}
548+
549+
550+
<h3>Parameters:</h3>
551+
<ul>
552+
<li><span class="parameter">search</span>
553+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
554+
search to parse
555+
</li>
556+
</ul>
557+
558+
<h3>Returns:</h3>
559+
<ol>
560+
561+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
562+
a table of all search parameters (a string:string map).
563+
</ol>
564+
565+
<h3>Raises:</h3>
566+
error when search or key is not a string
567+
568+
569+
<h3>Usage:</h3>
570+
<ul>
571+
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>)
572+
<span class="keyword">local</span> result = search.<span class="function-name">decode</span>(<span class="string">"a=b&amp;c=d&amp;e=f&amp;a=g"</span>)</pre>
573+
</ul>
574+
575+
</dd>
576+
<dt>
577+
<a name = "decode_all"></a>
578+
<strong>decode_all (search)</strong>
579+
</dt>
580+
<dd>
581+
Decodes all search parameters and returns a Lua table of them.</p>
582+
583+
<p> Given the following query string:
584+
&ldquo;a=b&amp;a=c&amp;d=e&rdquo;"</p>
585+
586+
<p> The following table is returned:
587+
{
588+
a = { &ldquo;b&rdquo;, &ldquo;c&rdquo; },
589+
d = { &ldquo;e&rdquo; },
590+
}
591+
592+
593+
<h3>Parameters:</h3>
594+
<ul>
595+
<li><span class="parameter">search</span>
596+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
597+
search to parse
598+
</li>
599+
</ul>
600+
601+
<h3>Returns:</h3>
602+
<ol>
603+
604+
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
605+
a table of all search parameters (a string:table [array] map).
606+
</ol>
607+
608+
<h3>Raises:</h3>
609+
error when search or key is not a string
610+
611+
612+
<h3>Usage:</h3>
613+
<ul>
614+
<pre class="example"><span class="keyword">local</span> search = <span class="global">require</span>(<span class="string">"resty.ada.search"</span>)
615+
<span class="keyword">local</span> result = search.<span class="function-name">decode_all</span>(<span class="string">"a=b&amp;a=c&amp;d=e"</span>)</pre>
616+
</ul>
617+
458618
</dd>
459619
</dl>
460620
<h2 class="section-header "><a name="Remove_Functions"></a>Remove Functions </h2>
@@ -823,7 +983,7 @@ <h3>Usage:</h3>
823983
</div> <!-- id="main" -->
824984
<div id="about">
825985
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
826-
<i style="float:right;">Last updated 2024-08-20 21:17:51 </i>
986+
<i style="float:right;">Last updated 2024-09-03 15:49:45 </i>
827987
</div> <!-- id="about" -->
828988
</div> <!-- id="container" -->
829989
</body>

‎lib/resty/ada.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local setmetatable = setmetatable
2626

2727

2828
local _OMITTED = 0xffffffff
29-
local _VERSION = "1.0.1"
29+
local _VERSION = "1.1.0"
3030

3131

3232
local function parse_component(c, raw)

‎lua-resty-ada-1.0.1-1.rockspec ‎lua-resty-ada-1.1.0-1.rockspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package = "lua-resty-ada"
2-
version = "1.0.1-1"
2+
version = "1.1.0-1"
33
source = {
44
url = "git+https://github.com/bungle/lua-resty-ada.git",
5-
tag = "v1.0.1",
5+
tag = "v1.1.0",
66
}
77
description = {
88
summary = "LuaJIT FFI bindings to Ada — WHATWG-compliant and fast URL parser",

0 commit comments

Comments
 (0)
Please sign in to comment.