apache velocity to ignore \n in token? - velocity

Is there a way to tell apache velocity to ignore \n in tokens?
For the following password token (line number 2)
The output is on line number 6 and 7
update
someone marked this as Duplicate, its not, in my case the new line are in the token

I've just checked the following example:
#set($value="123\n123")
<label>$value<\label>
The printout is: "123\n123"
As long as you print out your variable in quotes it should print it as is and not convert the "\n" to a new line.

Related

EOL error - Escape Newline Characters in a Python String

I wish to hand chunks of text to an API. However, I cant as python wont let me handle the text if I try saving as a variable. How do I do it? Thank you
prompt = (f"xxxx
xxxx
xxxxx
xxxx
xxxx")
I tried code below to overcome the EOL error but it didnt work. I want to do it automatically not manually add backslashes as prompt is text which will change for input to an api. This made no difference
def escape_newline(string):
return string.replace("\n", "\\n")
prompt= scape_newline(prompt)
print (prompt)
This comes up with:
prompt = (f"xxxx
^
SyntaxError: EOL while scanning string literal
Use triple strings instead of single ones. That allows for strings to take place over multiple lines :)
prompt = (f"""xxxx
xxxx
xxxxx
xxxx
xxxx""")
print(prompt)

Is there a special case in Apache2 when calling a CGI and the URI includes a single query string parameter without a value?

Today I got an error and was very surprised to get it since everything looked just fine...
I have a CGI written in C++ which accepts URIs with a query string. The query string is what selects the page, etc. The CGI is installed in the standard location for an Ubuntu installation:
/usr/lib/cgi-bin/snapmanager.cgi
Today I was finishing up adding a Login screen and once logged in, I wanted to add a logout link. The link simply adds ?logout at the end of the URI:
http://www.example.com/cgi-bin/snapmanager.cgi?logout
That failed.
Checking the error log, I got an error saying that "logout" actually appeared on the command line. Rather surprising, if you ask me! I tried with:
http://www.example.com/cgi-bin/snapmanager.cgi?logout=now
and everything worked as expected. No logout on the command line.
I also tried:
http://www.example.com/cgi-bin/snapmanager.cgi?logout&host=foo
And that worked too. Again, no logout on the command line.
However, if I switch the parameters position it fails again:
http://www.example.com/cgi-bin/snapmanager.cgi?host=foo&logout
So it looks like Apache2 calls my CGI with the logout query string as a parameter on the command line when that one query string name is defined last.
Just in case, I tried to add dashes at the start of the name, and sure enough, that appears as a command line switch in my logs!
error:snapmanager.cgi: option --logout is not supported.
Really scary. This is a huge security risk if you know of a switch that can "tweak things your way"...
Is that documented somewhere?
I actually found the answer in RFC3875 in paragraph 4.4
4.4. The Script Command Line
Some systems support a method for supplying an array of strings to the CGI script. This is only used in the case of an 'indexed' HTTP query, which is identified by a 'GET' or 'HEAD' request with a URI query string that does not contain any unencoded "=" characters. For such a request, the server SHOULD treat the query-string as a search-string and parse it into words, using the rules
search-string = search-word *( "+" search-word )
search-word = 1*schar
schar = unreserved | escaped | xreserved
xreserved = ";" | "/" | "?" | ":" | "#" | "&" | "=" | "," |
"$"
After parsing, each search-word is URL-decoded, optionally encoded in a system-defined manner and then added to the command line argument list.
If the server cannot create any part of the argument list, then the server MUST NOT generate any command line information. For example, the number of arguments may be greater than operating system or server limits, or one of the words may not be representable as an argument.
The script SHOULD check to see if the QUERY_STRING value contains an unencoded "=" character, and SHOULD NOT use the command line arguments if it does.
Emphasis Mine

Printing Expected Token Type XXX when a parsing error occurs

I would like to be able to print this error message using Ragel
=> Parsing error found at position line:col, Integer expected instead.
Is that possible with Ragel?
Best regards
I haven't gotten too far into error handling in Ragel just yet, but I would expect that if you use the error action embedding operators as specified in section 3.2.3 of the Ragel 6.9 Guide, that would override the default message.
You can get the line number by incrementing a counter at each newline, and get the column by taking the current position and subtracting the position of the previous newline, something like this:
newline = '\n' %{ ++lineCounter; linePosition = p; }
action ErrorHandler {
column = p - linePosition + 1;
// Print error message here using lineCounter and column
}
main := (allsortsofstuff | newline)* <>err(ErrorHandler);
Of course, the above may require a bit of tweaking based on exactly what you're doing, but at least it's a starting point.

Antlr, get last line from token

I have a token definition that can contain multiple lines (something like multi line comments).
I can use the .line attribute to get the line where the token starts, but I need to
know where the token end.
Is it possible to get the last line of the token?
You can change the line number of a token by placing the (Java) code-block {$line=getLine();} at the end of the rule.
So, for multi-line comments, that would look like this:
COMMENT
: '/*' .* '*/' {$line=getLine();}
;
causing the method getLine() of the token COMMENT to return the line number the sub-string "*/" occurred on.

inserting character in file , jython

I have written a simple program where to read the first 4 characters and get the integer of it and read those many character and write xxxx after it . Although the program is working the only issues instead of inserting the character , its replacing.
file = open('C:/40_60.txt','r+')
i=0
while 1:
char = int(file.read(4))
if not char: break
print file.read(char)
file.write('xxxx')
print 'done'
file.close()
I am having issue with writing data .
considering this is my sample data
00146456135451354500107589030015001555854640020
and expected output is
001464561354513545xxxx00107589030015001555854640020
but actually my above program is giving me this output
001464561354513545xxxx7589030015001555854640020
ie. xxxx overwrites 0010.
Please suggest.
Files do not support an "insert"-operation. To get the effect you want, you need to rewrite the whole file. In your case, open a new file for writing; output everything you read and in addition, output your 'xxxx'.