script associated as svg

Post here if you feel others can duplicate your so discovered "bug"

Moderator: Forum moderators

Post Reply
User avatar
AntonioPt
Posts: 160
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 73 times
Been thanked: 33 times

script associated as svg

Post 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

Why astronauts use Linux
Because you can't open windows in space

Burunduk
Posts: 244
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 6 times
Been thanked: 122 times

Re: script associeted as svg

Post 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.

User avatar
MochiMoppel
Posts: 1116
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: script associeted as svg

Post 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.

Burunduk
Posts: 244
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 6 times
Been thanked: 122 times

Re: script associeted as svg

Post 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
User avatar
MochiMoppel
Posts: 1116
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: script associeted as svg

Post 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
User avatar
AntonioPt
Posts: 160
Joined: Wed Aug 11, 2021 7:41 pm
Has thanked: 73 times
Been thanked: 33 times

Re: script associeted as svg

Post 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

Why astronauts use Linux
Because you can't open windows in space

Post Reply

Return to “Bug Reports”