rejetto forum
Software => HFS ~ HTTP File Server => Topic started by: habazlam on January 13, 2007, 07:17:53 AM
-
Hi rejetto,
Assume that I'm doing something like this in .tpl:
....onClick="SomeFunction('%filename%')"...., where SomeFunction() prosesses STRING %filename% in some manner.
Now imagine that %filename% is equal to O'Reilly - Writing HFS Modules with Perl and C.chm :)
Obviously, I get a syntax error if I the "'" (apostroph) symbol is not encoded (certainly, there are other symbols that must be encoded for this case).
Of course, there are a lot of tricks to make a workaround for this kind of errors, but as a result, the JavaScript code in .tpl becomes unnecessarily complex.
This is the reason of my suggestion of the %filename-encoded% symbol.
BTW, thanks a lot for the HFS project: I was so impressed that began to develop a single-page HTML/DOM version of .tpl in my spare time :)
-
ok, please give me a full list of char.s to be encoded, and for each one the desired encoding.
and do it soon because the stable version is about to be published.
-
These two are essential:
' = %27
" = %22
I suppose these might also be worth encoding?
! = %21
( = %28
) = %29
-
i'm unsure this encoding is suitable for javascript context.
i mean, if he doesn't use the filename for making an URL, but for other purposes, this encoding may be inappropriate.
hasn't javascript a way to encode characters inside strings?
PHP uses \xHH where HH is hexadecimal code. AFAIK, also C uses this method.
-
A function could be written to encode a string by searching through it for any matches
and switching them to the new value, but javascript is slow and it would be far less
redundant and better for the page load if it was done automatically by HFS. We've had
this problem before on ToG. It would only cost 2 extra bytes per symbol changed if
it was done with HFS, but it would take an entire line and a slow javascript execution
to do it that way.
-
i think you misunderstood.
the thing i'm talking about requires no extra processing in javascript.
in php "A" and "\x41" is exactly the same thing for the programmer.
it's a different source for the same thing, i'll have a string made with one byte/char.
-
indeed, i just tried
document.write('Test \x41');
this thing is exactly the same as
document.write('Test A');
i would introduce a symbol %filename-js% with ' and " encoded. is it enough?
-
Hi rejetto,
i would introduce a symbol %filename-js% with ' and " encoded. is it enough?
Sure. Formally speaking, only string delimiters must be encoded inside %filename-js%:
<script type="text/javascript">
document.write('Test \x27<br>');
document.write('Test \x22<br>');
</script>
But I have to point you to the fact that theoretically the symbols in .tpl may be defined by .tpl developer as JavaScript fragments too, and in this case he/she may want to use JavaScript "escape sequences". So, you should isolate the first two ones from such replacement in other HFS functions (if you're going to use this replacement function in other pieces of HFS code, of course ;) ):
>>>> \' Single quotation mark
>>>> \" Double quotation mark
\\ Backslash
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\ddd Octal sequence (3 digits: ddd)
\xdd Hexadecimal sequence (2 digits: dd)
\udddd Unicode sequence (4 hex digits: dddd)
-
you should isolate the first two ones
isolate? what you mean? to have two different encodings? if so, what's the gain?
-
isolate? what you mean? to have two different encodings? if so, what's the gain?
In other words, just make such replacements only in %filename-js% and other native symbols, generated by HFS you may want to introduce, not in user-defined ones.
Example:
[progress-upload-file]
document.getElementById('PBFile').innerHTML = '%filename%'+'Some string with some substrings \"quoted\" in \'different\' manners';
....and so on
Please note that theoretically both apostroph and double quote signs may appear in [progress-upload-file] in several syntax contexts (also the apostroph sign may be contained in %filename%) in this case. If you'll begin to sort these things out on the server side, a huge source of bugs may be created - just leave user-defined symbols for the .tpl developer's responsibility.
-
i don't see how this can be a problem.
ALL will remain the same, BUT i will introduce the new symbol %filename-js% to be used in place of %filename% within javascript.
do you see any problem?
-
Just don't touch user-defined symbols :)
-
can you tell me what a user-defined symbol is?
-
I meant that in the HFS/tpl context "symbol" is a kind of macro definition, right? From the other hand, there is the list of "symbols", which are generated by HFS, and a .tpl developer can't change them. So, these two parts of HFS symbols may be called as "server-defined" and "user-defined" - just for convenience :)
-
truly, i still don't understand what a user-defined symbol is.
can you please make an example (or two)?
-
Hi rejetto,
It was just my attmpt of of classification your "symbols" :)
For example, %filename% may be called "server defined symbol", but apparently %unauthorized% is totally "user-defined".
-
%unauthorized% doesn't exist :)
maybe %style% is an example of user-defined symbol?