The @urlencode function doesn't seem to URL encode

Aug 28, 2008
124
4
The issue is that @urlencode doesn't seem to encode properly. Let's say somebody goes to the main Google page and searches for "C#". This is a parameter that should be URL-encoded as "C%23", which is precisely what the main Google page does. When I use @urlencode[C#] in the latest version of TakeCommand (13.00.28 x64), however, it gives me "23" as a result. The help file makes it sound like it should correctly encode an entire string:

Encode a string for Internet transmission, replacing non-alphanumeric characters with their %xx hex representation.

So I don't understand how it can take "C#" as an argument and spit back "23". Could somebody help me understand? Or is this a bug? Thanks in advance!
 
May 20, 2008
11,424
99
Syracuse, NY, USA
On Thu, 10 Nov 2011 11:09:28 -0500, Phileosophos <> wrote:

|So I don't understand how it can take "C#" as an argument and spit back "23". Could somebody help me understand? Or is this a bug? Thanks in advance!

It seems OK here (13.00.28/32-bit/Win7)/

Code:
v:\> setdos /x-4

v:\> echo %@urlencode[C#]
C%23

v:\> setdos /x+4

v:\>
 
Aug 28, 2008
124
4
Here is the text copied out of a TakeCommand session:

C:\> echo %@urlencode[C#]
C

C:\> echo %@urlencode["C#"]
23

I've checked by using the batch file debugger as well, working on on the assumption that maybe the resulting '%' was somehow screwing up the echo command, but it's not. I can't seem to get a properly encoded URL, and I haven't a clue why.
 

rconn

Administrator
Staff member
May 14, 2008
12,365
150
> Here is the text copied out of a TakeCommand session:
>
> C:\> echo %@urlencode[C#]
> C

WAD -- that gets translated to C%23, and the parser then does further
variable expansion on the result. %23 is interpreted as an empty argument
to ECHO and gets removed.


> C:\> echo %@urlencode["C#"]
> 23

WAD - that gets translated to %22C%23%22, and %22C% is parsed as an empty
argument, 23 is assumed to be a literal argument, and %22 is interpreted as
an empty argument.

ECHO is a bad way to display arguments with embedded %'s.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
rconn wrote:
| ...
| ECHO is a bad way to display arguments with embedded %'s.

This works:

echo "%@urlencode[C#]"

but of course it displays the quotation marks: "C%23".

The SAFEECHO command of C. Dye's plugin SafeChars.dll behave exactly as
ECHO...
--
HTH, Steve
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
rconn wrote:
| ...
| ECHO is a bad way to display arguments with embedded %'s.

This works:

echo "%@urlencode[C#]"

but of course it displays the quotation marks: "C%23".

The SAFEECHO command of C. Dye's plugin SafeChars.dll behave exactly as ECHO...

The args are expanded before SAFEECHO ever sees them. I do, however, have an alternative to @URLENCODE:

HTags Plugin

It uses the same basic idea as SafeChars: the percent signs are replaced with 'fake' percent signs, which get translated back to ASCII when you redirect the resulting string into a file.
 
May 20, 2008
11,424
99
Syracuse, NY, USA
On Thu, 10 Nov 2011 17:25:06 -0500, Steve Fabian <> wrote:

|This works:
|
|echo "%@urlencode[C#]"

That shouldn't work and it doesn't here.

Code:
v:\> echo "%@urlencode[C#]"
"C"

Have you forgotten about a prior "SETDOS /X-4"?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
From: vefatica
| On Thu, 10 Nov 2011 17:25:06 -0500, Steve Fabian <> wrote:
|
|| This works:
||
|| echo "%@urlencode[C#]"
|
| That shouldn't work and it doesn't here.
|...
| Have you forgotten about a prior "SETDOS /X-4"?

I sure did! Discovered long after posting.

This does work with SETDOS/X0 (i.e., interpret everything):
echo %@safeexp[@urlencode[C#]]
and correctly displays C%23. As Charles wrote, SAFEECHO receives the string only after the percent sign is mangled, but @SAFEEXP[] generates it in a safe mode.
--
Steve
 

rconn

Administrator
Staff member
May 14, 2008
12,365
150
> ---Quote (Originally by rconn)---
> ECHO is a bad way to display arguments with embedded %'s.
> ---End Quote---
> Er... what would be a good way to do it?

Well, assuming you actually *needed* to do it (and I doubt you would), I'd
assign the result of the function to a var, turn off expansion with SETDOS,
and then echo it.
 
Aug 28, 2008
124
4
ECHO is a bad way to display arguments with embedded %'s.

I realize that, which is precisely why I mentioned I get the very same thing when using the function in the batch file debugger or anywhere else. I've been trying to come up with a good way to write batch files that launch well-formatted URLs on the basis of user input, and I don't see any good way to use the @urlencode function to do that. If you do, please explain how it's intended to be used; as it is, I don't see how it's useful. Thanks in advance.
 
Nov 2, 2009
294
6
Chile
www.farah.cl
Well, assuming you actually *needed* to do it (and I doubt you would), I'd
assign the result of the function to a var, turn off expansion with SETDOS,
and then echo it.

Sure, it's not typical in a CMD/TCC environment, but in HTML processing it is a common sight; there are many situations where a special char ('%' here) needs to be treated as a regular character. Perhaps there should be a %@percentencode[string] function that will "escape" the percentage (by adding the second '%') so it can be displayed or passed around.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
From: mfarah
| Sure, it's not typical in a CMD/TCC environment, but in HTML
| processing it is a common sight; there are many situations where a
| special char ('%' here) needs to be treated as a regular character.
| Perhaps there should be a %@percentencode[string] function that will
| "escape" the percentage (by adding the second '%') so it can be
| displayed or passed around.

Look in HELP -> TCC -> Variables and Functions -> Functions -> Functions by Category -> Binary Buffers.
--
HTH, Steve
 
Aug 28, 2008
124
4
For sake of clarity, here's the batch file on which I'm working. The point is to enable commands of the form "WebSearch arg1 arg2 arg3" that will invoke a given search engine.

iff %#==0 then
echo Usage: WebSearch arg1 arg2 arg3 ...
quit
endiff

set url=http://www.google.com/search?q=%1

do count=2 to %#
set url=%url%^+%[%count]
enddo

echo Launching search URL: %url%
start %url%
unset url

That works as it is, but it goes wrong when using arguments that need to be URL encoded (e.g., C#). If you can explain how I might put the @urlencode function to work, I'd appreciate it. Thanks!
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
That works as it is, but it goes wrong when using arguments that need to be URL encoded (e.g., C#). If you can explain how I might put the @urlencode function to work, I'd appreciate it. Thanks!

Something like this, perhaps?

Code:
@echo off
setlocal
setdos /x-4

iff %# == 0 then
   echo Usage: WebSearch arg1 arg2 arg3 ...
   quit
endiff

set url=http://www.google.com/search?q=

do count = 1 to %#
   set arg=%[%count]
   set arg=%@urlencode[%arg]
   iff %count == 1 then
      set url=%url%%arg
   else
      set url=%url+%arg
   endiff
enddo

echo Launching search URL: %url
start %url
endlocal
 
Similar threads
Thread starter Title Forum Replies Date
M Is there a way to urlencode strings in v10? Support 0
vefatica Documentation Function parameters Support 0
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Joe Caverly How to? Get name of current LIBRARY function? Support 4
x13 WeekNum function? Support 3
Joe Caverly No blank line in TEXT...ENDTEXT in a LIBRARY function Support 8
cgunhouse Ctrl-C from within a library function Support 6
C email[string] function Support 10
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
Dick Johnson Using the @instr function Support 5
vefatica '}' in a library function? Support 3
D Can the argument to RETURN be a function expansion? Support 3
J Trouble with @full[] function. Support 3
Fross Quick Function Question Support 17
vefatica Quoting @Function parameters? Support 0
Joe Caverly Debugging a LIBRARY function Support 10
Steve Pitts Documentation @CAPI function summary Support 0
x13 %x$ in function Support 3
thorntonpg @eval function, interesting results any explanation? Support 3
x13 Function to get interface user-defined name? Support 10
vefatica Fixed Help @FUNCTION, missing paragraph Support 8
Mordachai Variable followed by function constantly failing... Support 5
nickles Call a complex function Support 13
M Fixed Cannot use the "Browse..." function in "Find files/text" dialogbox Support 2
R Function #IDOW returns only 2 characters Support 10
T scrput `` in alias or function Support 2
S International characters - TYPE vs %@LINE function Support 5
JohnQSmith WAD @REPEAT function Support 15
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
A pdir function usage Support 3
nikbackm FUNCTION with variable number of arguments Support 17
S %@REGQUERY function Support 1
Dan Glynhampton Documentation v15 help: Error on @TRIMALL function page Support 0
M Why doesn't this @Field function work? Support 0
fpefpe How to? user function Support 1
M Why is this function getting these results in these circumstances? Support 6
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
M How to? Just verification for what I think I know regarding "Function"... Support 4
Frank How to? need help with "function" Support 10
Joe Caverly How to? Function Key With INPUT Support 5
M How to? "Function" and "%[xxx]" Support 7
M Kind of a out-of-curiosity question re. the "Function" command... Support 5
M Simple question about "Function" command... Support 4
M Just a curiosity question related to the "Function" command... Support 2
C not sure of windows registry function use Support 2
J issue to have "if" inside function Support 3
Frank is the search-function in VIEW working? Support 2
M Weird @Index function result... Support 7

Similar threads