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

Change message encoding to support URLs with ? #47

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

Michcioperz
Copy link
Contributor

@Michcioperz Michcioperz commented Jan 4, 2025

Before this change, if I request to play the URL

http://192.168.0.10/test.mp3?auth=something

through Home Assistant, it will result in this message being sent:

heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth%3Dsomething

but despite saying in CLI specification that special characters in arguments need to be encoded, HEOS seems to take the url argument and pass it to the stream server verbatim, as demonstrated by the nginx log resulting from this command:

Jan 04 12:03:27 lillia nginx[351316]: lillia nginx: 192.168.0.209 - - [04/Jan/2025:12:03:27 +0100] "GET /test.mp3?auth%3Dsomething HTTP/1.1" 404 146 "-" "AvegaMediaServer/2.0 Linux/2.6"

I've been playing URLs with ? in them for some months now by inserting them into the HEOS command without quoting them, for example:

heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth=something

This seems to be consistent with the requirement that url be the last argument, because then the controller can treat the rest of the command as URL without processing it.

This change introduces special handling of the url argument, so that it bypasses quoting in addition to being the last argument.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • Tests have been added/updated. No exclusions in .coveragerc permitted.
  • README.MD updated (if necessary)

Before this change, if I request to play the URL

    http://192.168.0.10/test.mp3?auth%3Dsomething

through Home Assistant, it will result in this message being sent:

    heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth%3Dsomething

but despite saying in CLI specification that special characters in
arguments need to be encoded, HEOS seems to take the url argument
and pass it to the stream server verbatim, as demonstrated by the
nginx log resulting from this command:

    Jan 04 12:03:27 lillia nginx[351316]: lillia nginx: 192.168.0.209 - - [04/Jan/2025:12:03:27 +0100] "GET /test.mp3?auth%3Dsomething HTTP/1.1" 404 146 "-" "AvegaMediaServer/2.0 Linux/2.6"

I've been playing URLs with ? in them for some months now by inserting
them into the HEOS command without quoting them, for example:

    heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth=something

This seems to be consistent with the requirement that url be the last
argument, because then the controller can treat the rest of the command
as URL without processing it.

This change introduces special handling of the url argument, so that it
bypasses quoting in addition to being the last argument.
Copy link
Owner

@andrewsayre andrewsayre left a comment

Choose a reason for hiding this comment

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

Nice job! Thank you!

Is there an open HA issue? If so, I'll cut a new release of the library to bump in HA.

@andrewsayre andrewsayre merged commit bc7fe5d into andrewsayre:dev Jan 5, 2025
3 of 4 checks passed
@Michcioperz
Copy link
Contributor Author

Mmm, not to my knowledge. Honestly I saw the issue and dug down to the source until I could find it. I see there is home-assistant/core#107442 (comment) where this problem is mentioned, but it's only a half of that issue's cause, the other being the character limit.

@andrewsayre
Copy link
Owner

@Michcioperz thank you! I'll get an update in HA this week!

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.

2 participants