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

[BUG] Component._encode ignores parameters if value is native #557

Closed
5 tasks done
Zocker1999NET opened this issue Sep 19, 2023 · 5 comments · Fixed by #559
Closed
5 tasks done

[BUG] Component._encode ignores parameters if value is native #557

Zocker1999NET opened this issue Sep 19, 2023 · 5 comments · Fixed by #559

Comments

@Zocker1999NET
Copy link
Contributor

Describe the bug

Component._encode ignores the given parameters if the value is already of a native type (see code in question). IMO this is unexpected behavior. This also seems unexpected for the dependent library caldav, where it leads to a RELTYPE to be fully ignored if the passed UID is of type vText (see python-caldav/caldav#334).

To Reproduce

(I’m not familiar with this library as I only discovered this issue through discovering python-caldav/caldav#334, so the reproducing code is not fully complete.)

import icalendar

todo_1  # assume minimal working vTODO
todo_2  # assume other minimal working vTODO

todo_2.add(
    "RELATES-TO",
    todo_1["uid"],
    parameters={"RELTYPE": "DEPENDS-ON"},
)
print(todo_2.to_ical())

In the output, the RELATES-TO is added, as specified.
However, its missing the parameter RELTYPE=DEPENDS-ON.

Expected behavior

Use the specified parameters (replace or append already existing ones on the native type) or, at least, throw a warning or error that parameter will be ignored.

Environment

  • OS: Debian GNU/Linux trixie/sid
  • Python version: Python 3.11.5
  • icalendar version: 5.0.8

Additional context

  • I tested it with the latest version pip3 install https://github.com/collective/icalendar.git
  • I attached the ICS source file or there is no ICS source file
@niccokunzmann
Copy link
Member

niccokunzmann commented Sep 19, 2023 via email

@Zocker1999NET
Copy link
Contributor Author

Hey, I’m currently writing the tests and I’m unsure with following case:

If a native object with parameters is to be _encoded with further parameters, what would you propose on what should happen:

  1. merge old & new parameters
    • would only overwrite in the case of the same property
    • however, can lead to parameters creeping their way to properties where they should not be used
  2. overwrite old parameters with new ones
    • potentially removes properties someone wanted to keep

I’m not sure what is the better choice as both seem equally reasonable to me. What’s your opinion on that?

Full Example

Assume following property value with parameters:

val = _encode("X-SOURCE", "SGFsbG8gV2VsdCE=", props={"ENCODING": "BASE64", "LANG": "en", "X-IS-SOURCE": "1"})

Following call would happen to _encode:

val = _encode("X-TARGET", val, props={"LANG":"de", "X-IS-TARGET": "1"})

Both possibilities for the parameters seem reasonable:

  1. {"ENCODING": "BASE64", "LANG": "de", "X-IS-SOURCE": "1", "X-IS-TARGET": "1"}
    • important ENCODING is kept
    • potentially incompatible/unexpected X-IS-SOURCE is kept as well
  2. {"LANG": "de", "X-IS-TARGET": "1"}
    • important ENCODING is lost
    • potentially incompatible/unexpected X-IS-SOURCE is lost

@jacadzaca
Copy link
Collaborator

Hi @Zocker1999NET , for me the first option seems more logical, since val stores state and I'd expect _encoding further parameters to imply the keeping of old ones

Zocker1999NET added a commit to Zocker1999NET/icalendar that referenced this issue Sep 24, 2023
Signed-off-by: Felix Stupp <felix.stupp@banananet.work>
Zocker1999NET added a commit to Zocker1999NET/icalendar that referenced this issue Sep 24, 2023
@niccokunzmann
Copy link
Member

@jacadzaca would you like to create a new release?

@jacadzaca
Copy link
Collaborator

@niccokunzmann sure thing :)

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 a pull request may close this issue.

3 participants