Orchard cms token json - orchardcms

I would like to format a json payload in a workflow activity. I use the new {Text.JavaScriptEncode} to enclose my properties in {}. I should do it wrong because the tokens are not evaluated anymore. So if i use
{Text.JavaScriptEncode}{
"Courriel":{FormSubmission.Field:Courriel}
{Text.JavaScriptEncode}}
It ends with the following value:
{
"Courriel":{FormSubmission.Field:Courriel}
}
So the {FormSubmission.Field:Courriel} is not evaluated. If i don't specify {Text.JavaScriptEncode} before the first {, nothing is rendered (empty string).
I'm using Orchard 1.10.1.0

You might need to turn on the Tokenizers HashMode.
I haven't tested your token but I'm pretty sure the tokenizer tries to evaluate
this as a token and fails:
{"Courriel":{FormSubmission.Field:Courriel}
With hashMode enabled your code will look like this:
#{Text.JavaScriptEncode}{
"Courriel":#{FormSubmission.Field:Courriel}
#{Text.JavaScriptEncode}}

Related

Using TokenStreamRewriter to insert tokens after lexing but before parsing

Using ANTLR 4.9.2 for C++.
Depending on the first tokens I might need to insert some tokens before parsing. My approach (simplified)
antlr4::ANTLRInputStream antlrIs(properlyEscaped);
Lexer lexer(&antlrIs);
antlr4::CommonTokenStream tokens(&lexer);
antlr4::TokenStreamRewriter tokenStreamRewriter(&tokens);
if (!(tokens.LA(1) == Lexer::MY_SPECIAL_TOKEN))
{
tokenStreamRewriter.insertBefore(tokens.LT(1), string("begin"));
}
Parser parser(&tokens);
Parser::FileContext* fileContext = parser.file();
Stepping with the debugger I see that the token is actually inserted. But the new token I insert seems be be ignored by parser.file().
How can I insert tokens so that parser.file() uses them?
TokenStreamRewriter just builds up a set of instructions for how the input stream should be changed. It doesn’t actually change the token stream itself.
Once you have executed all of your modification calls, you’ll need to call .getText() (or .getText(String programName)) to get get a String that has all of your changes incorporated. Then you can use that as the input to your Lexer to get a token stream containing your modifications.

Return response according to a common json schema

How can I make standard json keys schema for multiple API service.
What if on original response I want to map to specific keys?
Maybe adding or removing keys too?
I'd like to have same json keys output for all api services
for example: api service output:
{ "hello" : "word" }
but i want to response:
{"foo" : originalResponse.hello }
Thanks
I do not understand why the downvotes, the question seems legit to me.
In any case, you can achieve the use case by using the body modifier plugin we offer. Although it's not an official one, it should provide all you need to both add are move keys on a JSON payload based on any Javascript evaluable expression.
Cheers!

Swagger API "required" - how much is this required?

I've created a Swagger (on nodejs/express) test API with this specification (only relevant part):
...
parameters:
- name: name
in: query
required: true
type: string
...
But I can call the url with empty paramter, for example
http://localhost/test?name=
And it works without any problem, throws no exception or any other sign. Why?
If I make a similar call from the terminal via curl or via postman, it works as well. I parsed the query from the request object and found that in this case, the query parameter is interpreted as an empty string.
Making the call via SwaggerUI is different though, as the UI will actually not make the call UNLESS the query field has a value.
Try doing console.log(req.query); in your handler. You will probably see {name: ''}. Which is legitimate, just that the value of name is an empty string.
Look at JSON4 here: Representing null in JSON. So name IS defined, but it's empty.
You will probably need to do a check for empty string values.
I hope this helps!

gatling combining transform with jsonpath

I'm trying to extract a security_token from this response :
{}&&{"containers":{"userID":"p8admin","connected":true,"desktop":"icm"},
"userid":"p8admin",
"user_displayname": "p8admin",
"security_token":"-1829880900612241155",
"messages":[{"adminResponse":null,
"moreInformation":null,
"explanation":null,
"number":"0",
"userResponse":null,
"text":"p8admin connect\u00e9."
}]
}
I've tried combining transform and jsonPath :
.check(bodyString.transform(_.split("&&")(1)).jsonPath("&.security_token").saveAs("security_token"))
but i get this error :
value jsonPath is not a member of com.excilys.ebi.gatling.core.check.MatcherCheckBuilder
Let me know if there is a simple way to achieve this.
Thanks
From the documentation on checks:
This API provides a dedicated DSL for chaining the following steps:
defining the check
extracting
transforming
verifying
saving
Since the response isn't valid JSON, you'll need to use bodyString as the type. You can then transform and then save, but you can't go back to step 1. You can parse the value you need out of the JSON during the transform step.
As Stéphane pointed out, the easiest way to get the value is to use a regex check and extract the security_token value directly, as long as you don't need the rest of your JSON object for any logic.
I have the same problem, I used the regex() function like this :
.check(regex(""""security_token":"(.*)",""").saveAs("security_token"))

how to rewrite search[] to something else with htaccess

I have created a search form with get method. But when the url looks like this search.php?search[] or search?search[] (mod_rewrite) then I get a sql fattal error. It's passing an array and I want to avoid that problem.
my question is how do I redirect a person from that url to search.php
It sounds like you are directly passing the ?search[] query string variable into your SQL. mod_rewrite won't fix this for you... what if I decide to call your page with http://www.yoursite.com/search.php?search=;DROP TABLE users;? You simply aren't able to use mod_rewrite to predict all the bad kinds of input that a user can come up with.
Your code needs to be doing input validation and sanitization. You must assume that everything your script receives from the user is malicious and dangerous. That includes all data inside $_GET, $_POST and $_COOKIE.
The right solution here is to check that $_GET['search'] is a valid value to be passing to your SQL. Something like:
if (is_string($_GET['search']) && ! empty($_GET['search']) {
//escape the input properly using your database-specific method, e.g.:
$searchParam = mysql_real_escape_string($_GET['search']);
//run your query with the escaped data
}
At a minimum, that would ensure that your passed in search variable was not an empty string.

Resources