map directive in nginx work only in first variant - nginx

I try to use map directive.
I have 2 vars and if first var exist set it to new var, or if only second var exist, set it to new var.
My config:
map "$arg_arg1:$cookie_1" $new_var {
"~^.*:" $arg_arg1;
"~:.*$" $cookie_1;
default "new";
}
Work only in first situation.

The sequence .* also matches zero characters, so your first regex matches any string containing a :, including those that begin with a :.
Use ^.+: to guarantee at least one character before the : or just .: (as the anchor is not really necessary).
If the cookie value may contain a :, you may want to use ^[^:]+: instead.

My working config:
map "$cookie_1:$arg_arg1" $new_var {
default "new";
"~:.*$" $arg_arg1;
"~*^.*:$" $cookie_1;
}

Related

NGINX how to check if last part of an URI consist of 32 symbols and also fits into regexp [a-z0-9] using map {}?

There is an URI /part1/part2/partX/md5
How to extract using map {} last part of URI and check its length ( eq 32 symbols ) and then check does it fits into regexp [0-9a-z].
EDIT: Adding quotes around the regex should allow {32} to be used.
Not a very satisfying approach, but it works:
map $request_uri $count32 {
~/(?<last>[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z])$ $last;
}
if ($count32) {
return 200 "Last component has 32 characters: $count32
";
}

Loadrunner Parameters in JSON String

I'm trying to use a parameter inside of a JSON string, and would like to use an inner parameter to replace an GUID. I've changed the default parameter start and end characters since curly braces are used in JSON.
I've tried to do something like this, where the json param contains my json which is similar to this below.
{"DashboardGUID":"<Dash_GUID>"}
request_json = lr_eval_string("<json>");
lr_save_string(request_json, "request_json_param");
I'm expecting the lr_eval_string to replace the with the GUID that's in this parameter, what's the best why of replacing this ID in my JSON String?
Not sure what you are asking but I will put this here in case someone comes here in the future:
main.c
Action()
{
lr_eval_json("Buffer/File=my_json.json", "JsonObject=MJO",LAST);
lr_json_stringify("JsonObject=MJO","Format=compact", "OutputParam=newJsonBody",LAST);
lr_save_string(lr_eval_string(lr_eval_string("{newJsonBody}")),"tmp");
web_reg_find("Text={mydate}",LAST);
web_rest("POST",
"URL=http://myServer.microfocus.com/url",
"Method=POST",
"EncType=raw",
"Body={tmp}",
HEADERS,
"Name=Content-Type", "Value=application/json", ENDHEADER,
LAST);
return 0;
}
my_json.json
{
"LastActionId": 0,
"Updated": "{mydate}"
}
Okay so instead of doing what I'm thinking above I ended up creating an array of char's with this {"DashboardGUID":"<Dash_GUID>", someotherdata:"123"} in 10 different positions within the array. I then randomly selected an element from this array and when doing the lr_eval_string the parameter was replaced.
Hopefully this makes sense those looking to do something similar.

Is it possible to turn off case insensitivity using pattern only?

Regex has set option IgnoreCase. Is it possible to turn off case insensitivity using pattern only (like negation of (?i))?
In example below, find pattern for which result would be "aBaaaBBaaB".
string pattern = "???";
string input = "aAaaaAAaaA";
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
var result = regex.Replace(input, "B");
You can turn off options inline by using - before the option. E.g. the negation of (?i) is (?-i):
a minus sign (-) before an option or set of options turns those options off. For example, (?i-mn) turns case-insensitive matching (i) on, turns multiline mode (m) off, and turns unnamed group captures (n) off.

Flex 4.5 - How do you strip tags?

How do you strip (HTML) tags from a String in Flex 4.5 / 4.6?
I don't think there's an inbuilt function to strip the tags like in php.
However, you could use a regular expression to remove all text between < and >
var r:RegExp=/<\/??.*?\/??>/g;
I gotta run now, but if you could follow my line of thought:
While the string tests positive for the regexp, replace the occurrence with an empty string
That should remove all occurrences of this type:
<tag>
<tag />
</tag>
EDIT
var h:String="<html><head><title>Hello World</title></head><body><h1>Hello</h1>Hey there, what's new?</body></html>";
var r:RegExp=/<\/??.*?\/??>/s; //s=dotall to match . to newline also
while(r.test(h)) {
h=h.replace(r, ""); //Remember, strings are immutable, so you h.replace will not change the value of h, so you need to reassign the return to h
}
trace(h);
OUTPUT:
Hello WorldHelloHey there, what's new?

Test existence of xml attribute in as3

What is the best method to test the existence of an attribute on an XML object in ActionScript 3 ?
http://martijnvanbeek.net/weblog/40/testing_the_existance_of_an_attribute_in_xml_with_as3.html is suggesting to test using
if ( node.#test != node.#nonexistingattribute )
and I saw comments suggesting to use:
if ( node.hasOwnProperty('#test')) { // attribute qtest exists }
But in both case, tests are case sensitive.
From the XML Specs : "XML processors should match character encoding names in a case-insensitive way" so I presume attribute name should also be match using a case-insensitive comparison.
Thank you
Please re-read your quote from the XML specs carefully:
XML processors should match character
encoding names in a case-insensitive
way
This is in chapter 4.3.3 of the specs describing character encoding declarations, and it refers only to the names present in the encoding value of the <?xml> processing instruction, such as "UTF-8" or "utf-8". I see absolutely no reason for this to apply to attribute names and/or element names anywhere else in the document.
In fact, there is no mention of this in section 2.3 of the specs, Common Syntactic Constructs, where names and name tokens are specified. There are a few restrictions on special characters and such, but there is absolutely no restriction on upper and lower case letters.
To make your comparison case-insensitive, you will have to do it in Flash:
for each ( var attr:XML in xml.#*) {
if (attr.name().toString().toLowerCase() == test.toLowerCase()) // attribute present if true
}
or rather:
var found:Boolean = false;
for each ( var attr:XML in xml.#*) {
if (attr.name().toString().toLowerCase() == test.toLowerCase()) {
found = true;
break;
}
}
if (found) // attribute present
else // attribute not present
How about using XML's contains() method or XMLList's length() method ?
e.g.
var xml:XML = <root><child id="0" /><child /></root>;
trace(xml.children().#id.length());//test if any children have the id attribute
trace(xml.child[1].#id.length());//test if the second node has the id attribute
trace(xml.contains(<nephew />));//test for inexistend node using contains()
trace(xml.children().nephew.length());//test for inexistend node using legth()

Resources