Encode only spaces in jmeter GUI - http

I read a csv file for input in my jmeter test plan. I name the first variable in the row query.
I need it to encode spaces as %20 not +. Using the __urlencode() function like ${__urlencode(${query})} encodes the spaces as + the same way selecting the encode option on the parameter does in the above screenshot.

I don't think this is something you're really want as encoding the URL is not only about spaces.
You should use encodeURIComponent() function (or its equivalent). The way of calling it in JMeter via __javaScript function will look like:
${__javaScript(encodeURIComponent("${query}"),)}
If you just need to replace spaces with %20 you can do it with __groovy() funciton like:
${__groovy(vars.get('query').replaceAll(' '\, '%20'),)}
Demo:
See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.

Related

How to parse #{TEST TAGS} into only the Tags, eliminating current formatting?

Situation.. I have two tags defined, then I try to output them to the console. What comes out seems to be similar to an array, but I'd like to remove the formatting and just have the actual words outputted.
Here's what I currently have:
[Tags] ready ver10
Log To Console \n#{TEST TAGS}
And the result is
['ready', 'ver10']
So, how would I chuck the [', the ', ' and the '], thus only retaining the words ready and ver10?
Note: I was getting [u'ready', u'ver10'] - but once I got some advice to make sure I was running Python3 RobotFramework - after uninstalling robotframework via pip, and now only having robotframework installed via pip3, the u has vanished. That's great!
There are several ways to do it. For example, you could use a loop, or you could convert the list to a string before calling log to console
Using a loop.
Since the data is a list, it's easy to iterate over the list:
FOR ${tag} IN #{Test Tags}
log to console ${tag}
END
Converting to a string
You can use the evaluate keyword to convert the list to a string of values separated by a newline. Note: you have to use two backslashes in the call to evaluate since both robot and python use the backslash as an escape character. So, the first backslash escapes the second so that python will see \n and convert it to a newline.
${tags}= evaluate "\\n".join($test_tags)
log to console \n${tags}

How to process latex commands in R?

I work with knitr() and I wish to transform inline Latex commands like "\label" and "\ref", depending on the output target (Latex or HTML).
In order to do that, I need to (programmatically) generate valid R strings that correctly represent the backslash: for example "\label" should become "\\label". The goal would be to replace all backslashes in a text fragment with double-backslashes.
but it seems that I cannot even read these strings, let alone process them: if I define:
okstr <- function(str) "do something"
then when I call
okstr("\label")
I directly get an error "unrecognized escape sequence"
(of course, as \l is faultly)
So my question is : does anybody know a way to read strings (in R), without using the escaping mechanism ?
Yes, I know I could do it manually, but that's the point: I need to do it programmatically.
There are many questions that are close to this one, and I have spent some time browsing, but I have found none that yields a workable solution for this.
Best regards.
Inside R code, you need to adhere to R’s syntactic conventions. And since \ in strings is used as an escape character, it needs to form a valid escape sequence (and \l isn’t a valid escape sequence in R).
There is simply no way around this.
But if you are reading the string from elsewhere, e.g. using readLines, scan or any of the other file reading functions, you are already getting the correct string, and no handling is necessary.
Alternatively, if you absolutely want to write LaTeX-like commands in literal strings inside R, just use a different character for \; for instance, +. Just make sure that your function correctly handles it everywhere, and that you keep a way of getting a literal + back. Here’s a suggestion:
okstr("+label{1 ++ 2}")
The implementation of okstr then needs to replace single + by \, and double ++ by + (making the above result in \label{1 + 2}). But consider in which order this needs to happen, and how you’d like to treat more complex cases; for instance, what should the following yield: okstr("1 +++label")?

Is it possible to disable Command Substitution in Bash?

Is it possible to disable Command Substitution in Bash?
I want to pass a string containing several backticks characters as command-line argument to a program, without trailing backslashs or quoting the string.
Thank you.
I assume there is a misconception which grounds your question. Quoting is most likely the solution to your situation. But maybe you haven't found the right way of quoting yet or similar.
If your dangerous string shall be verbatim (without quoting or escaping) in the source code, you can put it in a separate file and read it from there:
dangerous_string=$(cat dangerous_string_file.txt)
If it shall be passed without interpretation to a command, use the double quotes to prevent interpretation:
my_command "$dangerous_string"
If you have to pass it to a command which needs to receive a quoted version of your string because it is known to carelessly pass the string without using sth like the double quotes to prevent interpretation, you can always use printf to get a quoted version:
quoted_dangerous_string=$(printf "%q" "$dangerous_string")
careless_command "$quoted_dangerous_string"
If all these options do not help in your situation, please explain in more detail where your problem lies.

Plone configuration

Plone is showing the special chars from my mother language (Brazilian Portuguese) in its pages. However, when I use a spt page I created it shows escape sequences, e.g.:
Educa\xc3\xa7\xc3\xa3o
instead of
Educação
(by the way, it means Education). I'm creating a python function to replace the escape sequences with the utf chars, but I have a feeling that I'm slaving away without need.
Are you interpolating catalog search results? Those are, by necessity (the catalog cannot handle unicode) UTF-8 encoded.
Just use the .decode method on strings to turn them into unicode again:
value = value.decode('utf8')
A better way should be to use safe_unicode function https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/utils.py#L458
from Products.CMFPlone.utils import safe_unicode
value = safe_unicode(value)

How I encode the ugly string?

I have a string that is:
!"#$%&'()*+,-./0123456789:;?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[]\^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª« ®¯°±²³´µ¶•¸¹º»¼½¾¿ÀÁÂÃÄÅàáâäèçéêëìíîïôö÷òóõùúý
I post that to service and used Htmlencode, then I get a result:
!#$%&'()* ,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~����������� ���������•������������������������������������
it isn't result that i need,how i get original string? thanks!
Your string is not ASCII, so you are either using a string to represent binary data, or you're not maintaining awareness of multi-byte encoding. In any case, the simplest way to deal with any Internet-based technology (HTTP, SMTP, POP, IMAP) is to encode it as 7-bit clean. One common way is to base64-encode your data, send it across the wire, then base64-decode it before trying to process it.
I believe this is what you're looking for:
!"#$%&&apos;()*+,-./0123456789:;?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[]\\^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«®¯°±²³´µ¶•¸¹º»¼½¾¿ÀÁÂÃÄÅàáâäèçéêëìíîïôö÷òóõùúý
You just need to use a better html entity/encoding library or tool. The one I used to generate this is from Ruby - I used the HTML Entities library. The code I wrote to do this follows. I had to put your text in input.txt to preserve Unicode (there was an EOF character in the string), but it worked great.
require 'rubygems'
require 'htmlentities'
str = File.read('input.txt')
coder = HTMLEntities.new
puts coder.encode(str, :named)

Resources