Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Updated _parsePath to handle query strings better. - #1

Merged
yanshcherbakovatredspace merged 1 commit into
SpringRoll:masterfrom
gopherwood:master
Jul 12, 2016
Merged

Updated _parsePath to handle query strings better.#1
yanshcherbakovatredspace merged 1 commit into
SpringRoll:masterfrom
gopherwood:master

Conversation

@probityrules

Copy link
Copy Markdown

Per this discussion, I've updated the SoundJS _parsePath method to handle query string variations better.

In most cases, the new regex can find the extension for a sound file whether it's a direct link or part of a query string.

Below I've listed a wide assortment of urls the updated method can handle, including the three properties it outputs.

Path name src extension
music.mp3 "music.mp3" "music.mp3" "mp3"
../music.mp3 "music.mp3" "../music.mp3" "mp3"
../sub/dir/music.mp3 "music.mp3" "../sub/dir/music.mp3" "mp3"
/from/root/music.mp3 "music.mp3" "/from/root/music.mp3" "mp3"
http://web.site/sub/dir/music.mp3 "music.mp3" "http://web.site/sub/dir/music.mp3" "mp3"
music.mp3?v=1.1.1 "music.mp3" "music.mp3?v=1.1.1" "mp3"
../sub/dir/music.mp3?with=query-parameters "music.mp3" "../sub/dir/music.mp3?with=query-parameters" "mp3"
music.mp3?with/confusing/filename.ogg "music.mp3" "music.mp3?with/confusing/filename.ogg" "mp3"
audio?music.mp3 "music.mp3" "audio?music.mp3" "mp3"
audio.php null null null
audio.php?music.mp3 "music.mp3" "audio.php?music.mp3" "mp3"
../sub/dir/audio?music.mp3 "music.mp3" "../sub/dir/audio?music.mp3" "mp3"
/from/root/audio?music.mp3 "music.mp3" "/from/root/audio?music.mp3" "mp3"
http://web.site/sub/dir/audio.php?music.mp3 "music.mp3" "http://web.site/sub/dir/audio.php?music.mp3" "mp3"
audio?../sub/dir/music.mp3 "music.mp3" "audio?../sub/dir/music.mp3" "mp3"
audio?music.mp3&v=1.1.1 "music.mp3" "audio?music.mp3&v=1.1.1" "mp3"
audio?file=music.mp3&v=1.1.1 "music.mp3" "audio?file=music.mp3&v=1.1.1" "mp3"
audio?v=1.1.1&file=music.mp3 null null null
audio?big-parameter_name=/big/file/name/music.mp3&v=1.1.1 "music.mp3" "audio?big-parameter_name=/big/file/name/music.mp3&v=1.1.1" "mp3"
unsupported/music.wma?with=OGGalternative "music.wma" "unsupported/music.ogg?with=OGGalternative" "ogg"

Two fail: one has no audio file type specified, and the other fails since the method is only checking the first valid parameter of the query string for a file type. It's checking against the first parameter's "1.1.1", but I'm not certain of a concise and foolproof way to fix the general case for an indeterminate set of parameters.

Let me know what you think!

Comment thread src/soundjs/Sound.js
var name = '';
var ext = '';
var origExt = '';
if (s.SUPPORTED_EXTENSIONS.indexOf(match[5]) >= 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to stay consistent with the code style convention, brackets should be on the next line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the code in this file keeps the brackets in the same line, the original line 1203 being an exception. I'm happy to change it, but I just want to make certain since dropping it down will be inconsistent with the rest of this file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, my bad, you are correct. Springroll follows that convention but this is the CreateJS fork. So disregard.

@yanshcherbakovatredspace

yanshcherbakovatredspace commented Jul 12, 2016

Copy link
Copy Markdown

Just noted something really minor, just to stay consistent with the code styling conventions of the rest of the code.

I don't see any issues at first glance.

Could you also include the built library please?

Also, could you please tell me of your method that you used to test the different cases? Did you use a unit test? If so, could you please provide it?

@probityrules

Copy link
Copy Markdown
Author

Yes, I created a basic unit test: I wasn't aware whether SoundJS is set up with a unit testing framework, so I performed it in the console:

var testParsePath = function () {
    var o = {};
    for (var a in arguments) {
        o[arguments[a]] = createjs.Sound._parsePath(arguments[a]) || {name: null, src: null, extension: null};
    }
    return o;
}
console.table(testParsePath('music.mp3', '../music.mp3', '../sub/dir/music.mp3', '/from/root/music.mp3', 'http://web.site/sub/dir/music.mp3', 'music.mp3?v=1.1.1', '../sub/dir/music.mp3?with=query-parameters', 'music.mp3?with/confusing/filename.ogg', 'audio?music.mp3', 'audio.php', 'audio.php?music.mp3', '../sub/dir/audio?music.mp3', '/from/root/audio?music.mp3', 'http://web.site/sub/dir/audio.php?music.mp3', 'audio?../sub/dir/music.mp3', 'audio?music.mp3&v=1.1.1', 'audio?file=music.mp3&v=1.1.1', 'audio?v=1.1.1&file=music.mp3', 'audio?big-parameter_name=/big/file/name/music.mp3&v=1.1.1', 'unsupported/music.wma?with=OGGalternative'))

@andrewstart

Copy link
Copy Markdown

Looks awesome to me.

@yanshcherbakovatredspace

yanshcherbakovatredspace commented Jul 12, 2016

Copy link
Copy Markdown

Awesome thanks! Yep, looks good!

@yanshcherbakovatredspace
yanshcherbakovatredspace merged commit 052ba07 into SpringRoll:master Jul 12, 2016
@probityrules probityrules mentioned this pull request Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants