HTML Problem

C

CyberDroog

At least I think it is... I have been playing with HttpFileServer
v2.0beta23 (http://www.rejetto.com/sw/) along with some user created
templates.

One of the template has a problem with file names that contain a single
quote character. The forum for the software doesn't seem to have much
traffic, so maybe someone here can see what the problem is and how to fix
it.

An example line from the code to display a file name: <tr class="mout"
onmouseover="this.className='mover'" onmouseout="this.className='mout'"
onclick="location.href='%item-url%'">

The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes. When it comes across a folder name such
as: CD's, that seems to translate in the code to 'CD's', and the code
chokes. Clicking the link does nothing, and reloading the file list can
produce an "Error expecting ;" for every file or folder name that contains
a single quote.

Is there a simple way to fix this?
 
M

Martin Jay

CyberDroog said:
At least I think it is... I have been playing with HttpFileServer
v2.0beta23 (http://www.rejetto.com/sw/) along with some user created
templates.
[Snip]

The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes. When it comes across a folder name such
as: CD's, that seems to translate in the code to 'CD's', and the code
chokes. Clicking the link does nothing, and reloading the file list can
produce an "Error expecting ;" for every file or folder name that contains
a single quote.

It's probably getting upset about the ' in CD's.
Is there a simple way to fix this?

Rename the directory so that is doesn't contain a ' in the name. Maybe
to CDs instead.
 
C

CyberDroog

CyberDroog said:
At least I think it is... I have been playing with HttpFileServer
v2.0beta23 (http://www.rejetto.com/sw/) along with some user created
templates.
[Snip]

The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes. When it comes across a folder name such
as: CD's, that seems to translate in the code to 'CD's', and the code
chokes. Clicking the link does nothing, and reloading the file list can
produce an "Error expecting ;" for every file or folder name that contains
a single quote.

It's probably getting upset about the ' in CD's.

Yes, that is what I said is causing the problem.
Rename the directory so that is doesn't contain a ' in the name. Maybe
to CDs instead.

Changing every file name on my system which contains a single quote
character isn't going to happen. It's just too common, especially in my
MP3 folders.
 
R

Robert Frost-Bridges

CyberDroog said:
Changing every file name on my system which contains a single quote
character isn't going to happen. It's just too common, especially in my
MP3 folders.

I'm not sure what OS you're running but I wouldn't have thought batch
renaming of files would be too difficult. I'm on Linux myself and I should
imagine it's just a one-liner at the command prompt. (but don't ask me
what).

regards,
 
S

Stan McCann

At least I think it is... I have been playing with HttpFileServer
v2.0beta23 (http://www.rejetto.com/sw/) along with some user created
templates.
The part: onclick="location.href='%item-url%' seems to be the
problem since it is surrounded by single quotes. When it comes
across a folder name such as: CD's, that seems to translate in the
code to 'CD's', and the code chokes. Clicking the link does
nothing, and reloading the file list can produce an "Error expecting
;" for every file or folder name that contains a single quote.

Is there a simple way to fix this?

This is off topic for this group as it is not an HTML issue.

With that said, your fix is to rename the directories. Although some
OSes will let you get away with it, ' is not a valid character for file
names on some OSes. There are many symbols that are valid, but a good
rule of thumb to go by is to use letters, numbers, -, _ and . only.
Stick to those and you will rarely, if ever, have file name problems.
 
C

CyberDroog

I'm not sure what OS you're running but I wouldn't have thought batch
renaming of files would be too difficult. I'm on Linux myself and I should
imagine it's just a one-liner at the command prompt. (but don't ask me
what).

I didn't mean to say it was difficult. I do batch renames all the time
because I'm kind of obsessive/compulsive about consistent and well-ordered
file names.

I meant to say that it's something I just won't do. A single quote
character is a legal character in a file name and I don't have any
intention of not using them because a bit of HTML can't deal with it.
I have other templates for HFS that work just fine.

I was just curious about the bit of code I posted. To fix it would, I
gather, require escaping the single quote characters that may appear in
file names. That's easy if the file names are explicitly defined. But
this is a variable - the code doesn't know if a file name will have a
single quote character, or how many of them.
 
C

CyberDroog

This is off topic for this group as it is not an HTML issue.

With that said, your fix is to rename the directories. Although some
OSes will let you get away with it, ' is not a valid character for file
names on some OSes. There are many symbols that are valid, but a good
rule of thumb to go by is to use letters, numbers, -, _ and . only.
Stick to those and you will rarely, if ever, have file name problems.

On what OSes would a single quote be an illegal character in a file name?
These directories are on a Win2k3 Server, but I haven't had any problems
accessing them with any other version of Windows, or DOS, or Mandriva
Linux. Though with Linux I am using KDE. I can't recall if I've tried
playing with such a file on the command line.

Doesn't matter though. I like them the way they are. ;)

The whole matter is academic really. I was just fiddling with a template
to see how it works and to figure out what to tweak to change features,
appearance, etc. As you pointed out, I know so little about it that I
wasn't aware that that portion of the code wasn't HTML. What is it,
javascript?

I suppose I can just dig in and rearrange the code such that the
%item-name% is no longer nested in quotes. That works fine in other
templates, though maybe because they are pure HTML.

--
"'Stupid' means one thing: threatening to the interests of the Democratic
Party. The more Conservative the Republican, the more vicious and
hysterical the attacks on his intelligence will be."

- Ann Coulter
 
R

rf

CyberDroog said:
The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes.

onclick='location.href="%item-url%";' ?

Cheers
Richard.
 
C

CyberDroog

onclick='location.href="%item-url%";' ?

That just changes the error message (unterminated string literal).

I've been thinking that, since %item-name% is a variable in which there is
no telling whether is contains a single quote, or how many, maybe I need a
function to search through it and replace all instance of a single quote
with an escape sequence.

--
One of the annoying things about believing in free will and individual
responsibility is the difficulty of finding somebody to blame your problems
on. And when you do find somebody, it's remarkable how often his picture
turns up on your driver's license.

- P.J. O'Rourke
 
N

Neredbojias

With neither quill nor qualm, CyberDroog quothed
I've been thinking that, since %item-name% is a variable in which there is
no telling whether is contains a single quote, or how many, maybe I need a
function to search through it and replace all instance of a single quote
with an escape sequence.

A regular expression replace would be a cinch.
 
K

kchayka

CyberDroog said:
The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes. When it comes across a folder name such
as: CD's

If you insist on using quote marks in file or folder names, you should
url-encode them in the HTML, i.e.

item-url = "CD%27s"

Do this with any character other than letters, numbers, dashes,
underscores or periods, and you won't have any browser troubles.
 
C

CyberDroog

If you insist on using quote marks in file or folder names, you should
url-encode them in the HTML, i.e.

item-url = "CD%27s"

Do this with any character other than letters, numbers, dashes,
underscores or periods, and you won't have any browser troubles.

The problem is that this is a dynamic process. The code simply reads any
folder/file tree it is pointed at.
 
M

Martin Jay

CyberDroog said:
At least I think it is... I have been playing with HttpFileServer
v2.0beta23 (http://www.rejetto.com/sw/) along with some user created
templates.
One of the template has a problem with file names that contain a single
quote character. The forum for the software doesn't seem to have much
traffic, so maybe someone here can see what the problem is and how to fix
it.
An example line from the code to display a file name: <tr class="mout"
onmouseover="this.className='mover'" onmouseout="this.className='mout'"
onclick="location.href='%item-url%'">
The part: onclick="location.href='%item-url%' seems to be the problem since
it is surrounded by single quotes. When it comes across a folder name such
as: CD's, that seems to translate in the code to 'CD's', and the code
chokes. Clicking the link does nothing, and reloading the file list can
produce an "Error expecting ;" for every file or folder name that contains
a single quote.

If you're willing to use Javascript, as you appear to be, there may be a
solution.

Assign %item-url% to a variable;

replace ' with %27 in the variable's contents;

then, replace %item-url% in onclick="location.href='%item-url%' with the
new variable name.
 
K

kchayka

CyberDroog said:
The problem is that this is a dynamic process. The code simply reads any
folder/file tree it is pointed at.

No excuse. PHP has a built-in function that does this, as do other
languages. And then there are always regular expressions...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top