Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3230: SmoothStreaming URLs that uses parenthesis '(...)' as part of … #3231

Closed
wants to merge 2 commits into from

Conversation

nahojkap
Copy link

@nahojkap nahojkap commented Sep 1, 2017

…the URL causes server side errors

Here is the suggested fix for #3230 in a pull request.

this.manifestUri = manifestUri == null ? null
: Util.toLowerInvariant(manifestUri.getLastPathSegment()).equals("manifest") ? manifestUri
: Uri.withAppendedPath(manifestUri, "Manifest");
this.manifestUri = manifestUri == null ? null : lastPathSegment.contains("manifest") && lastPathSegment.contains("(") && lastPathSegment.contains(")")) ? manifestUri : lastPathSegment.equals("manifest") ? manifestUri : Uri.withAppendedPath(manifestUri, "Manifest");
Copy link
Contributor

@ojw28 ojw28 Sep 4, 2017

Choose a reason for hiding this comment

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

  • Does this actually compile? What is lastPathSegment? It doesn't seem to be defined anywhere.
  • I'm not convinced about the logic. It matches all kinds of random things, like "xy)(manifest". Why not use Util.toLowerInvariant(manifestUri.getLastPathSegment()).matches("XXX") where "XXX" is a regular expression that more exactly describes what we consider a match?

Copy link
Author

Choose a reason for hiding this comment

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

You are right - apologies for that, very sloppy of me.

And a reg-exp would be a much more elegant solution - will update

@ojw28 ojw28 self-assigned this Sep 4, 2017
…rt of the URL causes server side errors: revised after comments
@nahojkap
Copy link
Author

nahojkap commented Sep 5, 2017

@ojw28 - updated the pull request - there is a duplication of the reg.exp used in Util.java and the SsMediaSource.java - not sure if you have a better, mode preferred place to put this or not.

Hope that is OK now.

Copy link
Contributor

@ojw28 ojw28 left a comment

Choose a reason for hiding this comment

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

Looks nicer, although there's a NPE in there I think ;).

this.manifestUri = manifestUri == null ? null
: Util.toLowerInvariant(manifestUri.getLastPathSegment()).equals("manifest") ? manifestUri
: Uri.withAppendedPath(manifestUri, "Manifest");
String lastPathSegment = Util.toLowerInvariant(manifestUri.getLastPathSegment());
Copy link
Contributor

Choose a reason for hiding this comment

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

This will NullPointerException is manifestUri is null.

Copy link
Author

Choose a reason for hiding this comment

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

You are right but by pulling together the reg-exp to check also for just 'manifest' we should be able to get rid of that local variable entirely.

: Uri.withAppendedPath(manifestUri, "Manifest");
String lastPathSegment = Util.toLowerInvariant(manifestUri.getLastPathSegment());
// Using a regexp here to allow for URLs which contain (..) as their last part, e.g. http://host/content.ism/manifest(filter=0) - see #3230
this.manifestUri = manifestUri == null ? null : lastPathSegment.equals("manifest") ? manifestUri : lastPathSegment.matches("manifest\\(.*\\)") ? manifestUri : Uri.withAppendedPath(manifestUri, "Manifest");
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be preferable to have a single regex that matches "manifest" and "manifest(...)". Something like "manifest(\\(.*\\))?" (I didn't check that's right!). Then you can get rid of the equals("manifest") case.

Copy link
Author

Choose a reason for hiding this comment

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

Will fix this

@@ -901,7 +901,8 @@ public static int inferContentType(String fileName) {
} else if (fileName.endsWith(".m3u8")) {
return C.TYPE_HLS;
} else if (fileName.endsWith(".ism") || fileName.endsWith(".isml")
|| fileName.endsWith(".ism/manifest") || fileName.endsWith(".isml/manifest")) {
|| fileName.endsWith(".ism/manifest") || fileName.endsWith(".isml/manifest")
|| Uri.parse(fileName).getLastPathSegment().matches("manifest\\(.*\\)")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to match if the .ism or .isml bit isn't there.

Copy link
Author

Choose a reason for hiding this comment

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

Would you prefer if this is pushed into a reg-exp as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ideally it would be a regex check directly on fileName (i.e. avoiding parsing as a uri, particularly given the method above converts from a uri into a string to call this method :)).

@ojw28
Copy link
Contributor

ojw28 commented Sep 20, 2017

I pushed ce7aaab to fix this, since this hadn't been updated in a while. Let us know on the corresponding issue if there are any problem. Thanks!

@ojw28 ojw28 closed this Sep 20, 2017
@google google locked and limited conversation to collaborators Jan 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants