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

lxa_iobus: server: fix string/integer type confusion in set_pin() #43

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

hnez
Copy link
Member

@hnez hnez commented Apr 11, 2024

The form encoded parameter value sent via POST request is parsed by aiohttp so it can be used in set_pin().
It is however passed in as string ("0", "1" or "toggle") so it will always be considered true-ish, resulting in the current implementation always turning the output on, even if "0" was requested.

Treat the value as integer instead (as long as it is not "toggle") and check that for true-ish-ness.

Fixes: 9236c1d introduced in #38.

TODO before merging:

  • Check if other form data handling in server.py is sound. It is unclear why this worked previously, because there was no type conversion in the code that 9236c1d replaced. There was a type conversion. I just overlooked it in the diff.

The form encoded parameter `value` sent via POST request is parsed
by aiohttp so it can be used in set_pin().
It is however passed in as string ("0", "1" or "toggle") so it will
always be considered true-ish, resulting in the current implementation
always turning the output on, even if "0" was requested.

Treat the value as integer instead (as long as it is not "toggle")
and check that for true-ish-ness.

Fixes: 9236c1d ("lxa_iobus: node: replace ad-hoc struct parsing ...
Signed-off-by: Leonard Göhrs <[email protected]>
@hnez
Copy link
Member Author

hnez commented Apr 11, 2024

I've checked the other endpoints and think they are not affected by this.

I've also found the change in 9236c1d that removed the string to integer type conversion, which is a bit hidden in the diff:
9236c1d#r140859939, because the control flow changed.

@hnez hnez requested a review from SmithChart April 11, 2024 10:52
@hnez hnez marked this pull request as ready for review April 11, 2024 10:52
@SmithChart SmithChart merged commit 2d8ba45 into linux-automation:master Apr 11, 2024
5 checks passed
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.

3 participants