Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-j
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-j
Commits
f758abf0
Unverified
Commit
f758abf0
authored
Sep 07, 2023
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a fallback argument to j.unquote()
parent
4d11868f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
11 deletions
+31
-11
vmod_j.c
src/vmod_j.c
+12
-5
vmod_j.man.rst
src/vmod_j.man.rst
+7
-4
vmod_j.vcc
src/vmod_j.vcc
+5
-2
vmod_j.vtc
src/vtc/vmod_j.vtc
+7
-0
No files found.
src/vmod_j.c
View file @
f758abf0
...
...
@@ -504,8 +504,15 @@ vmod_object(VRT_CTX, VCL_STRANDS s)
return
(
p
+
1
);
}
#define fail(ctx, fallback, ...) do { \
if (fallback != NULL) \
VSLb(ctx->vsl, SLT_Error, __VA_ARGS__); \
else \
VRT_fail(ctx, __VA_ARGS__); \
} while(0)
VCL_STRING
vmod_unquote
(
VRT_CTX
,
VCL_STRING
p
)
vmod_unquote
(
VRT_CTX
,
VCL_STRING
p
,
VCL_STRING
fallback
)
{
struct
vsb
vsb
[
1
];
const
char
*
err
=
NULL
;
...
...
@@ -515,15 +522,15 @@ vmod_unquote(VRT_CTX, VCL_STRING p)
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
*
p
!=
'"'
||
p
[
strlen
(
p
)
-
1
]
!=
'"'
)
{
VRT_fail
(
ctx
,
"j.unquote() argument missing quotes"
);
return
(
NULL
);
fail
(
ctx
,
fallback
,
"j.unquote() argument missing quotes"
);
return
(
fallback
);
}
p
++
;
WS_VSB_new
(
vsb
,
ctx
->
ws
);
if
(
vsbjunquot
(
vsb
,
p
,
&
err
)
&&
err
!=
NULL
)
{
VRT_fail
(
ctx
,
"j.unquote() error at: ...%.10s"
,
err
);
return
(
NULL
);
fail
(
ctx
,
fallback
,
"j.unquote() error at: ...%.10s"
,
err
);
return
(
fallback
);
}
r
=
WS_VSB_finish
(
vsb
,
ctx
->
ws
,
NULL
);
if
(
r
==
NULL
)
{
...
...
src/vmod_j.man.rst
View file @
f758abf0
...
...
@@ -39,7 +39,7 @@ SYNOPSIS
STRING object(STRING)
STRING unquote(STRING)
STRING unquote(STRING
, STRING fallback
)
INTRODUCTION
...
...
@@ -404,10 +404,13 @@ Deprecated alias for ``object()``.
.. _j.unquote():
STRING unquote(STRING)
----------------------
STRING unquote(STRING, STRING fallback=0)
-----------------------------------------
Utility function to decode JSON strings into UTF-8.
Utility function to decode JSON strings into UTF-8
If decoding fails and *fallback* is provided, the error is logged with
tag ``Error`` and *fallback* is returned. Otherwise, the VCL is failed.
WARNING
...
...
src/vmod_j.vcc
View file @
f758abf0
...
...
@@ -339,9 +339,12 @@ concatenation argument (strands) as key/value pairs.
$Alias obj object
$Function STRING unquote(STRING)
$Function STRING unquote(STRING
, STRING fallback=0
)
Utility function to decode JSON strings into UTF-8
Utility function to decode JSON strings into UTF-8.
If decoding fails and *fallback* is provided, the error is logged with
tag ``Error`` and *fallback* is returned. Otherwise, the VCL is failed.
WARNING
...
...
src/vtc/vmod_j.vtc
View file @
f758abf0
...
...
@@ -108,6 +108,10 @@ varnish v1 -vcl {
"C" + j.array("A" + 2 + j.object(j.nil()))
);
set resp.http.o4 = j.object(j.string("A") + j.object(j.nil()));
set resp.http.unok = j.unquote({""abc""});
set resp.http.unno = j.unquote("", j.null());
set resp.body = "";
return (deliver);
}
...
...
@@ -156,6 +160,9 @@ client c1 {
expect resp.http.o3 == \
"{\"A\":null,\"B\":{\"BB\":42.42e42,\"CC\":false,\"DD\":true},\"C\":[\"A\",2,{}]}"
expect resp.http.o4 == "{\"A\":{}}"
expect resp.http.unok == "abc"
expect resp.http.unno == "null"
} -start
logexpect l2 -v v1 -q "ReqURL ~ \"^/e-badutf\"" {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment