Page 1 of 1

script associated as svg

Posted: Sun Apr 09, 2023 10:14 pm
by AntonioPt

Hello to all,
I recently did a basic script to clean SVG files and when I gave myself the script instead of being recognized with a Bash file was recognized with an SVG

Here goes my code
#!/bin/sh

I noticed this bug in fossapup now
#<svg width = "100" height = "100">
for file in *; SED -RI 'S/<SVG.*/<svg width = "100" height = "100">/g' $ file; done

for file in *; SED -RI "/^\ r? $/D" $ file; done


Re: script associeted as svg

Posted: Mon Apr 10, 2023 12:52 am
by Burunduk

Confirmed on Fossapup64-9.5. This is a bug in rox-filer.

If a file with a .txt extension contains <svg somewhere inside, rox-filer knows it's a text file.
If the same file is renamed to have an unknown or no extension: file.txt -> file.foo - rox-filer thinks it's an svg image.

By the way, cleaning svg is not a trivial problem. Maybe scour can do this for you. It can be installed with the PPM on Fossa.


Re: script associeted as svg

Posted: Mon Apr 10, 2023 12:59 am
by MochiMoppel

@AntonioPt This is not a bug.

Your problem can occur when you give your script a name without a .sh extension.
In this case your system will have to look into your file to determine the file type. If it finds a string '<svg' withing the first 260 characters of the file it will determine that it is SVG image file and not a bash script. This happens in your case.
It doesn't help that your file starts with '#!/bin/sh' which you might think clearly defines it as a bash script. This is because your system checks for SVG files before it checks for shell script files.

If you don't want to use a .sh extension for your file there are a couple of tricks you can do to shield your script from false SVG association. For example instead of echo "<svg>blabla" you could write echo <"svg>blabla" or echo "<""svg>blabla". Just avoid the 4 consecutive characters <svg at the beginning of your script.

You can easily check if your file is recognizes as an image or a script file. Just pay attention to the file icon in a ROX-Filer window.

Edit: @Burunduk Our posts crossed. The problem occurs in all Puppy versions. I don't agree that this is a bug. Without a file extension there is nothing else ROX-Filer can and should do than consulting the mime magic file.


Re: script associeted as svg

Posted: Mon Apr 10, 2023 4:11 am
by Burunduk
MochiMoppel wrote: Mon Apr 10, 2023 12:59 am

The problem occurs in all Puppy versions. I don't agree that this is a bug. Without a file extension there is nothing else ROX-Filer can and should do than consulting the mime magic file.

It has a unique way to do that. These utilities should use the same magic but only search for <svg at the start:

Code: Select all

root# echo '<svg' >file
root# file file
file: SVG Scalable Vector Graphics image
root# file -i file
file: image/svg+xml; charset=us-ascii
root# xdg-mime query filetype file
image/svg+xml
root# 
root# echo '#<svg' >file
root# file file
file: ASCII text
root# file -i file
file: text/plain; charset=us-ascii
root# xdg-mime query filetype file
text/plain

Re: script associeted as svg

Posted: Mon Apr 10, 2023 5:38 am
by MochiMoppel
Burunduk wrote: Mon Apr 10, 2023 4:11 am

It has a unique way to do that. These utilities should use the same magic but only search for <svg at the start:

Not only at the start. They appear to check also for a valid XML header. ROX is less thorough but it still observes the rules of the magic file ... more or less ;)

Code: Select all

#  echo '<?xml version="1.0" encoding="UTF-8"?><svg' > /tmp/testo
#  file -b --mime-type /tmp/testo
image/svg+xml
#  rox -m /tmp/testo
image/svg+xml
# 
#  echo '<?xml bla><svg' > /tmp/testo
#  file -b --mime-type /tmp/testo
text/xml
#  rox -m /tmp/testo
image/svg+xml

Re: script associeted as svg

Posted: Mon Apr 10, 2023 12:40 pm
by AntonioPt
MochiMoppel wrote: Mon Apr 10, 2023 12:59 am

@AntonioPt This is not a bug.

Your problem can occur when you give your script a name without a .sh extension.
In this case your system will have to look into your file to determine the file type. If it finds a string '<svg' withing the first 260 characters of the file it will determine that it is SVG image file and not a bash script. This happens in your case.
It doesn't help that your file starts with '#!/bin/sh' which you might think clearly defines it as a bash script. This is because your system checks for SVG files before it checks for shell script files.

If you don't want to use a .sh extension for your file there are a couple of tricks you can do to shield your script from false SVG association. For example instead of echo "<svg>blabla" you could write echo <"svg>blabla" or echo "<""svg>blabla". Just avoid the 4 consecutive characters <svg at the beginning of your script.

You can easily check if your file is recognizes as an image or a script file. Just pay attention to the file icon in a ROX-Filer window.

Edit: @Burunduk Our posts crossed. The problem occurs in all Puppy versions. I don't agree that this is a bug. Without a file extension there is nothing else ROX-Filer can and should do than consulting the mime magic file.

Thankyou for explanation now i get it why this is happening