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

Implement RelationshipErrorHandler #1619

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

igitur
Copy link
Member

@igitur igitur commented Feb 21, 2021

Fixes #249
Depends on dotnet/Open-XML-SDK#887

The RelationshipErrorHandler requires modifying the package. It's an implicit assumption in ClosedXML that we don't do that when we load the package. Therefore, as a workaround, when an implementation of RelationshipErrorHandler is provided, the input stream is copied to a new MemoryStream before the loading continues. This enables the handler to rewrite the package as required without touching the user-supplied file or stream.

@twsouthwick
Copy link
Contributor

v2.12.3 should be available soon with the fix.

@igitur
Copy link
Member Author

igitur commented Feb 25, 2021

Thanks for the speedy fix, as usual, @twsouthwick

@igitur igitur force-pushed the issue249-relationshiprewriter branch from cef9272 to e8afa8e Compare February 26, 2021 14:27
@igitur igitur force-pushed the issue249-relationshiprewriter branch from e8afa8e to f76c253 Compare March 12, 2021 10:22
@igitur igitur force-pushed the issue249-relationshiprewriter branch 4 times, most recently from bd90b33 to cffc32a Compare March 14, 2021 16:25
@igitur
Copy link
Member Author

igitur commented Mar 14, 2021

@Pankraty Work in progress, but if you can start looking at this, it would be appreciated.

@igitur igitur force-pushed the issue249-relationshiprewriter branch from cffc32a to 6a43b5e Compare March 14, 2021 16:51
wip2
@Pankraty
Copy link
Member

Pankraty commented Jun 8, 2021

Sorry, this got lost among incoming messages.
I guess, first 4 commits can be safely merged as a separate PR.


public XLWorkbook(LoadOptions loadOptions)
{
EventTracking = loadOptions.EventTracking;
Copy link
Member

Choose a reason for hiding this comment

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

Do we still use EventTracking or we are keeping this for backward compatibility only? I thought, events processing was dropped long ago so maybe it's time to deprecate this flag?

Copy link
Member

Choose a reason for hiding this comment

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

Just checked - LoadOptions.EventTracking is only set and never read.

@@ -664,6 +664,8 @@ public XLWorkbook()
internal XLWorkbook(String file, Boolean asTemplate)
: this(new LoadOptions())
{
if (!asTemplate) throw new NotSupportedException();
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we fallback to ordinary loading? As a user, I would expect these two calls producing identical result:

var wb = new XLWorkbook(fileName);
var wb = new XLWorkbook(fileName, asTemplate: false);

Comment on lines +37 to +38
[TestCaseSource(nameof(MalformedFiles))]
public void CanSuccessfullyLoadMalformedFilesWithRemoveMalformedHyperlinksRelationshipErrorHandlerFactory(string file)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps, we should also have a test checking that opening these files without RemoveMalformedHyperlinksRelationshipErrorHandlerFactory fails. If that test starts to fail one day, that will be an indicator for us that the factory is not needed anymore and we can consider removing (deprecating) it.

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.

Invalid Hyperlink: Malformed URI is embedded as a hyperlink in the document.
3 participants