Giter Site home page Giter Site logo

Comments (30)

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024 2

Without any escaping as long as there is not a # it works
Using encodeURIComponet break everything, but if you were to unencode / it would probably work
Using encodeURI break nothing, works just as well as not escaping
Using escape breaks spacial Unicode characters

encodeURI does not touch these:
A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
the only characters that look to break this are # and ?

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Does it do any harm then? I have a folder # for all artist names starting with numbers or special characters. If I don't use encodeURIComponent, it won't play (it sees it as an anchor, instead of a folder). Of course, I can only replace #, but I wasn't sure if any other special chars did the same.

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

The problem it is escapes forward slashes so it will not work with sub folders
this is form my firefox console
screenshot_2018-06-02_08-22-57

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Forward slashes are used on a Windows HTTP server?

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

I am using a apache2 on my linux server: https://imgur.com/a/5CtPA

Did you have any issues with my version working?

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

does using the escape function instead work for you, that did not break it for me?
audio.src = escape(path);

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Strange, I thought the behavior of the deprecated escape() would mimic encodeURI() or encodeURIComponent(), but apparently it's a different flavor altogether. escape() works just fine over here, so if it also works in your use case, it's the best option. Thanks!

Apart from this, I also need to add a few lines of error handling when playback fails. I just want it to mark the non-played item and continue with the next, since a party player that stops playing instantly becomes a party pooper.

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

audio.src = encodeURI(path); also works for me

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Not for me in the # case, so escape() is best :-)

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

Did you have this issue is my version?

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Yeah, I did. Back then, I just added s.src=file.replace('#', '%23');.

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

b461afc

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024
  • Prevent encoding of \ in audio.src for Apache servers

that is the wrong slash

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

escape seems to break it with some unicode characters, here is one for you to try: 月

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

Using encodeURI seems to to not break anything here
encodeURIComponent is used for parameters like this
http://example.com/path/to/file?opt='+encodeURIComponent(string)+'&'+encodeURIComponent(string2)

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

I guess we should use this:
encodeURI(FILE_PATH).replace(/#/g,'%23');

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Wow, that's a thorough investigation. (Probably) definitively fixed in 1.0.2 now :-)

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

s.replace('#', '%23').replace('?', '%3F');
but what if there is more than one?

function safeURI(src){
   return encodeURI(src).replace(/#/g,'%23').replace(/\?/g,'%3F');
}

I feel like there is a way to use replace only once...

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

Dang, I need to get some sleep, not focused at all anymore.,, Either way, I feel using RegExp will inadvertedly introduce a whole new can of worms with RegExp's metacharacters, so simply using return s.split('#').join('%23').split('?').join('%3F'); is best for this occasion imho. I found my suspicion is documented on StackOverflow, too.

This solution isn't fast, but occurrences will be very limited anyway, so it shouldn't delay the script much at all.

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

StackOverflow link please

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript#comment27121391_1144788

There's a way around it, of course, but I'd rather keep the code more legible. I genuinely hate RegExp, because I keep being awed by its power while stunned and frustrated by its pickyness and lack of intuitiveness :-P

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

Knew there was a way to only use replace once

function safeURI(src){
   return encodeURI(src).replace(/[(#\?]/g,function(char){return escape(char);});
}

There are 10 kinds of people who understand regular expressions: them and us

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

encodeURI is to be on the safe side
encodeURI is intended to encode a entire url, it does not target ?, =, &, and # as these special url chars
? is used to send parameters to a server
= is used to separate parameters names from values
& is used to separate separate parameters
# is used for scrolling to elements on a page based on element IDs
I think we could escape both = and &, but browsers know if there has not been a ? symbol they are not being used for parameters
function safeURI(src){return encodeURI(src).replace(/[(\?=&#]/g,function(char){return escape(char);});}
In theory we should be able to use encode uri component and unescape every / if we do not want to escape a few more chars our self
function safeURI(src){return encodeURIComponent(src).replace(/%2F/g,'/');}
If this is used on a full link you need to decode : also
function safeURI(src){return encodeURIComponent(src).replace(/(%2F|%3A)/g,function(str){return decodeURIComponent(str);}); }


function safeURI(src){
   // escape additional chars method
   return encodeURI(src).replace(/[(\?=&#]/g,function(char){return escape(char);});
   // unescape necessary character
   return encodeURIComponent(src).replace(/%2F/g,'/');
   // unescape multiple chars to be safe
   return encodeURIComponent(src).replace(/(%2F|%3A)/g,function(str){return decodeURIComponent(str);});
}

And with that my regex cheat sheet has been consumed

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

config is null; easy fix; only need to add 4 chars
I do not think that was a waterfox issue, it was a there is no config data yet issue

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

True, but there wasn't any in Vivaldi either.

from music-folder-player.

GM-Script-Writer-62850 avatar GM-Script-Writer-62850 commented on May 28, 2024

firefox should behave the same, the only way for it not to is if the config option has not been set

it a very inconvenient to debug that part as it is set to save the config on page leave, so even if you clear it then reload it saves it and you do not get a cleran config

if you used the same config name i did in your version on the same server both pages share the same config data, if you used Vivaldi on your project then loaded mine on the same server you had a exist config that was not null

also according to a scratch pad test firefox would get this error also as this returns null:
JSON.parse(localStorage.getItem("someFakeStorageName-"+Math.random()))
if that does not return null the browser does not follow the standard

from music-folder-player.

ltguillaume avatar ltguillaume commented on May 28, 2024

I waited for Cookies Exterminator to clean up cookies & LS, but I guess it didn't take those instances. Sorry to have misinformed you.

Oh and no, I'm not using the same config name in my project.

from music-folder-player.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.