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

OFX Spec Compliance Fixes #332

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Holzhaus
Copy link

@Holzhaus Holzhaus commented Jan 11, 2025

This makes it possible to import the output of ofxstatement with Denaro. See #327 (comment) for detailed explanations.

Fixes #327.

encoded = str(encoded, "utf-8")
encoding = "cp1252"
encoded = etree.tostring(et.getroot(), encoding)
encoded = str(encoded, encoding)
Copy link
Owner

Choose a reason for hiding this comment

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

I assume this breaks any outputs with characters outside of cp1252 encoding (IOW, this will probably break ofxstatement for a lot of users, including me). This doesn't seem right.

Regarding the encoding, you seem to refer to some ancient OFX spec from 1999 in #327 (comment). We shouldn't be stuck with such an old version in 2025.

Copy link
Author

Choose a reason for hiding this comment

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

I suppose it depends on the support by other tools. If OFX 1.0.2 is more widely supported, it makes sense to stick with that unless there is a reason to upgrade.

The 1.0.2 spec talks about ENCODING:UNICODE, and the OFX 2.2 spec implies that this referred to UTF-8. Most tools (e.g. GnuCash) support UNICODE, we can just use that. OfxSharp which is used by Denaro does not support it, but I think this should be fixed upstream, not worked around here.

FYI, we are not the only ones struggling with OFX encoding: https://github.com/wesabe/fixofx/blob/1792d94697af682ca1d4a75cfefe98465d95a288/lib/ofx/document.py#L27-L42 😅

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I agree, just having it as UNICODE would be fine. From what I remember I didn't specifically chose OFX 1.0.2 for compatibility, but it was just what was in some sample file I used in initial implementation. So we can be flexible here, as long as consuming tools are ok with that.

For this case, I'm fine if the encoding would be UNICODE instead of UTF-8.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I noticed that the encoding is already configurable, so I made the OFX writer respect that. If "utf-8" is used, it will use ENCODING:UNICODE and CHARSET:NONE, if cp1252 is used it will use ENCODING:USASCII and CHARSET:1252.

For other charsets, it will try to handle this gracefully by using a nonstandard charset. Alternatively, we could raise an error.

@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch from afba71f to e21fde6 Compare January 12, 2025 12:53
Copy link
Owner

@kedder kedder left a comment

Choose a reason for hiding this comment

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

This looks good, just please fix the tests.

@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch 2 times, most recently from edcb14c to ebfe884 Compare January 12, 2025 22:29
@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch from ebfe884 to febd0c3 Compare January 12, 2025 22:30
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.

OFX cannot be imported by Denaro
2 participants