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

Simulate a FileOk handler when choosing an image file #1335

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

StephenMcConnel
Copy link
Member

@StephenMcConnel StephenMcConnel commented Aug 1, 2024

This enforces the image file filter even when users type or paste in a file path that defeats the filter. This fix is motivated by https://issues.bloomlibrary.org/youtrack/issue/BL-13552. Using the DialogAdapters interface prevents having an actual FileOk handler.


This change is Reviewable

@StephenMcConnel StephenMcConnel force-pushed the BL-13552-EnforceFileFiltering branch from cc4c4f8 to 5f048f8 Compare August 1, 2024 17:46
Copy link
Contributor

@andrew-polk andrew-polk left a comment

Choose a reason for hiding this comment

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

Thinking through the implications of semantic versioning here....
in one sense, this could be considered a breaking change if any client were expecting to allow the loophole of pasting whatever file you want. But given that the library won't do anything sensible (I assume) with other file types, I think we can probably rule that out.
I think I'm ok with considering this a bug fix.

This is a good compromise, btw. Good thinking!

Reviewed 2 of 2 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @StephenMcConnel)


CHANGELOG.md line 27 at r2 (raw file):

### Fixed

- [SIL.Window.Forms] When choosing a file in the ImageToolbox.AcquireImageControl, a FileOk handler is simulated that verifies the selected file passes the given filter.  Users can defeat the filter mechanism by pasting or typing the file name.  While the returned filename does not pass the filter, the dialog is reopened until the user either chooses a proper filename or cancels the dialog.  The native FileOk handler can prevent the dialog from closing: we can't achieve that.  (See BL-13552.)

I think this has to go into a new "Fixed" section under "Unreleased" instead of 14.1.1.


SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs line 110 at r1 (raw file):

						if (DialogResult.OK == dlg.ShowDialog(this.ParentForm))
						{
							// Simulate having a FileOk event handler that can cancel the OK button click.

Probably worth calling out that we would prefer to use FileOk but that it is tied up in DialogAdapters so not worth changing at this time.

Copy link

github-actions bot commented Aug 1, 2024

LibPalaso Tests

   17 files  ±0     17 suites  ±0   6m 29s ⏱️ - 1m 6s
4 883 tests +1  4 652 ✅ +1  231 💤 ±0  0 ❌ ±0 
4 902 runs  +1  4 658 ✅ +1  244 💤 ±0  0 ❌ ±0 

Results for commit de1a607. ± Comparison against base commit e8ce8b2.

♻️ This comment has been updated with latest results.

This enforces the image file filter even when users type or paste in
a file path that defeats the filter.  This fix is motivated by
https://issues.bloomlibrary.org/youtrack/issue/BL-13552.  Using the
DialogAdapters interface prevents having an actual FileOk handler.
@StephenMcConnel StephenMcConnel force-pushed the BL-13552-EnforceFileFiltering branch from 5f048f8 to de1a607 Compare August 1, 2024 18:14
Copy link
Member Author

@StephenMcConnel StephenMcConnel left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 3 files reviewed, 2 unresolved discussions (waiting on @andrew-polk)


CHANGELOG.md line 27 at r2 (raw file):

Previously, andrew-polk wrote…

I think this has to go into a new "Fixed" section under "Unreleased" instead of 14.1.1.

Good catch. My eyes saw "Fixed" but didn't see the version number above it.


SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs line 110 at r1 (raw file):

Previously, andrew-polk wrote…

Probably worth calling out that we would prefer to use FileOk but that it is tied up in DialogAdapters so not worth changing at this time.

Done.

Copy link
Contributor

@andrew-polk andrew-polk left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @StephenMcConnel)

@andrew-polk andrew-polk merged commit db9df03 into master Aug 1, 2024
4 of 5 checks passed
@andrew-polk andrew-polk deleted the BL-13552-EnforceFileFiltering branch August 1, 2024 18:25
Comment on lines +111 to +115
// We would prefer to actually use the event handler since that can prevent the
// dialog from closing, but we can't do that because of using DialogAdapters for
// cross-platform compatibility. It's not worth messing with DialogAdapters at
// this point just to get this feature, which might not be cross-platform.
if (!DoubleCheckFileFilter(dlg.Filter, dlg.FileName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need DialogAdapters given that we are no longer shipping Bloom (or other software) on Mono Linux? It would seem like a good idea to just remove the "cross-platform" code since it's not actually used and go with the simpler native implementation of FileOK for Windows.Forms. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

We thought Flex was still using the mono code in libpalaso. Is that incorrect?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you fact-check the following for me, @jasonleenaylor ?

FieldWorks won't be shipping a new version on mono linux, so we're safe to remove mono cross-platform code from libpalaso master and reduce complexity for everyone. I gather this PR would have been simpler without the mono requirement. We don't even have build infrastructure anymore to build FW mono on Linux.

WinForms in libpalaso should be assumed to be Windows-only runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes @megahirt you are correct. We have stopped packaging for linux and are focusing on rearchitecting with the hope handle future cross-platform versions without mono. Sorry for any extra effort that went in because that wasn't widely known. When I saw this comment I assumed Bloom was still shipping for linux with mono.

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.

4 participants