-
Notifications
You must be signed in to change notification settings - Fork 370
Add validations for storage pickers #5619
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
Merged
DinahK-2SO
merged 18 commits into
main
from
user/DinahK-2SO/StoragePickers_errorHandling
Jul 19, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ce6e055
validate the enums
DinahK-2SO 687f58c
validate filters and choices
DinahK-2SO 1935bd1
Merge branch 'main' of github.com:microsoft/WindowsAppSDK into user/D…
DinahK-2SO 60c0d78
localization files for local tests
DinahK-2SO 548cbe6
tests
DinahK-2SO 698d862
ValidatingFileTypeFilterVector
DinahK-2SO dd2c623
ValidatingFileTypeChoicesMap
DinahK-2SO 71d0016
ValidateSuggestedFileName
DinahK-2SO 338036f
Validate CommitButtonText and SettingsIdentifier
DinahK-2SO ae1e279
tests for validating the embedded null
DinahK-2SO f306fcb
Merge branch 'main' of github.com:microsoft/WindowsAppSDK into user/D…
DinahK-2SO a18c73b
revert changes on resources here (will have a separate PR for it)
DinahK-2SO 1ca3cc6
Merge branch 'main' into user/DinahK-2SO/StoragePickers_errorHandling
DinahK-2SO aa66d27
move vector and map construction to *picker.h
DinahK-2SO 9fa16af
update resource key
DinahK-2SO 924f5ae
add missing copyright headlines; add a localization fallback
DinahK-2SO 6a11bef
resolve comments: fix errors; remove localization fallback; graceful
DinahK-2SO 3e18954
Merge branch 'main' of github.com:microsoft/WindowsAppSDK into user/D…
DinahK-2SO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" | ||
#include "FileTypeChoicesMap.h" | ||
#include "FileTypeFilterVector.h" | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
FileTypeChoicesMap::FileTypeChoicesMap() | ||
{ | ||
} | ||
|
||
bool FileTypeChoicesMap::Insert(hstring const& key, winrt::Windows::Foundation::Collections::IVector<hstring> const& value) | ||
{ | ||
// Create a new FileTypeFilterVector and copy all values from the input vector | ||
auto validatingVector = make<FileTypeFilterVector>(); | ||
|
||
if (value) | ||
{ | ||
// Each Append call will validate the extension | ||
for (auto const& item : value) | ||
{ | ||
validatingVector.as<winrt::Windows::Foundation::Collections::IVector<hstring>>().Append(item); | ||
} | ||
} | ||
|
||
return m_innerMap.Insert(key, validatingVector); | ||
} | ||
|
||
winrt::Windows::Foundation::Collections::IVector<hstring> FileTypeChoicesMap::Lookup(hstring const& key) const | ||
{ | ||
return m_innerMap.Lookup(key); | ||
} | ||
|
||
uint32_t FileTypeChoicesMap::Size() const | ||
{ | ||
return m_innerMap.Size(); | ||
} | ||
|
||
bool FileTypeChoicesMap::HasKey(hstring const& key) const | ||
{ | ||
return m_innerMap.HasKey(key); | ||
} | ||
|
||
winrt::Windows::Foundation::Collections::IMapView<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> FileTypeChoicesMap::GetView() const | ||
{ | ||
return m_innerMap.GetView(); | ||
} | ||
|
||
void FileTypeChoicesMap::Remove(hstring const& key) | ||
{ | ||
m_innerMap.Remove(key); | ||
} | ||
|
||
void FileTypeChoicesMap::Clear() | ||
{ | ||
m_innerMap.Clear(); | ||
} | ||
|
||
winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>> FileTypeChoicesMap::First() const | ||
{ | ||
return m_innerMap.First(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include <winrt/Windows.Foundation.Collections.h> | ||
#include "FileTypeFilterVector.h" | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
struct FileTypeChoicesMap : implements<FileTypeChoicesMap, | ||
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>, | ||
winrt::Windows::Foundation::Collections::IIterable<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>>> | ||
{ | ||
FileTypeChoicesMap(); | ||
|
||
// IMap<hstring, IVector<hstring>> | ||
winrt::Windows::Foundation::Collections::IVector<hstring> Lookup(hstring const& key) const; | ||
uint32_t Size() const; | ||
bool HasKey(hstring const& key) const; | ||
winrt::Windows::Foundation::Collections::IMapView<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> GetView() const; | ||
bool Insert(hstring const& key, winrt::Windows::Foundation::Collections::IVector<hstring> const& value); | ||
void Remove(hstring const& key); | ||
void Clear(); | ||
|
||
// IIterable<IKeyValuePair<hstring, IVector<hstring>>> | ||
winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>> First() const; | ||
|
||
private: | ||
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> m_innerMap{ | ||
single_threaded_map<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>() }; | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" | ||
#include "FileTypeFilterVector.h" | ||
#include "PickerCommon.h" | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
FileTypeFilterVector::FileTypeFilterVector() | ||
{ | ||
} | ||
|
||
void FileTypeFilterVector::SetAt(uint32_t index, hstring const& value) | ||
{ | ||
PickerCommon::ValidateSingleFileTypeFilterElement(value); | ||
m_innerVector.SetAt(index, value); | ||
} | ||
|
||
void FileTypeFilterVector::InsertAt(uint32_t index, hstring const& value) | ||
{ | ||
PickerCommon::ValidateSingleFileTypeFilterElement(value); | ||
m_innerVector.InsertAt(index, value); | ||
} | ||
|
||
void FileTypeFilterVector::Append(hstring const& value) | ||
{ | ||
PickerCommon::ValidateSingleFileTypeFilterElement(value); | ||
m_innerVector.Append(value); | ||
} | ||
|
||
void FileTypeFilterVector::ReplaceAll(array_view<hstring const> items) | ||
{ | ||
// Validate all items before replacing | ||
for (auto const& item : items) | ||
{ | ||
PickerCommon::ValidateSingleFileTypeFilterElement(item); | ||
} | ||
m_innerVector.ReplaceAll(items); | ||
} | ||
|
||
hstring FileTypeFilterVector::GetAt(uint32_t index) const | ||
{ | ||
return m_innerVector.GetAt(index); | ||
} | ||
|
||
uint32_t FileTypeFilterVector::Size() const | ||
{ | ||
return m_innerVector.Size(); | ||
} | ||
|
||
winrt::Windows::Foundation::Collections::IVectorView<hstring> FileTypeFilterVector::GetView() const | ||
{ | ||
return m_innerVector.GetView(); | ||
} | ||
|
||
bool FileTypeFilterVector::IndexOf(hstring const& value, uint32_t& index) const | ||
{ | ||
return m_innerVector.IndexOf(value, index); | ||
} | ||
|
||
void FileTypeFilterVector::RemoveAt(uint32_t index) | ||
{ | ||
m_innerVector.RemoveAt(index); | ||
} | ||
|
||
void FileTypeFilterVector::RemoveAtEnd() | ||
{ | ||
m_innerVector.RemoveAtEnd(); | ||
} | ||
|
||
void FileTypeFilterVector::Clear() | ||
{ | ||
m_innerVector.Clear(); | ||
} | ||
|
||
uint32_t FileTypeFilterVector::GetMany(uint32_t startIndex, array_view<hstring> items) const | ||
{ | ||
return m_innerVector.GetMany(startIndex, items); | ||
} | ||
|
||
winrt::Windows::Foundation::Collections::IIterator<hstring> FileTypeFilterVector::First() const | ||
{ | ||
return m_innerVector.First(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include <winrt/Windows.Foundation.Collections.h> | ||
|
||
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation | ||
{ | ||
struct FileTypeFilterVector : implements<FileTypeFilterVector, | ||
winrt::Windows::Foundation::Collections::IVector<hstring>, | ||
winrt::Windows::Foundation::Collections::IIterable<hstring>> | ||
{ | ||
FileTypeFilterVector(); | ||
|
||
// IVector<hstring> | ||
hstring GetAt(uint32_t index) const; | ||
uint32_t Size() const; | ||
winrt::Windows::Foundation::Collections::IVectorView<hstring> GetView() const; | ||
bool IndexOf(hstring const& value, uint32_t& index) const; | ||
void SetAt(uint32_t index, hstring const& value); | ||
void InsertAt(uint32_t index, hstring const& value); | ||
void RemoveAt(uint32_t index); | ||
void Append(hstring const& value); | ||
void RemoveAtEnd(); | ||
void Clear(); | ||
uint32_t GetMany(uint32_t startIndex, array_view<hstring> items) const; | ||
void ReplaceAll(array_view<hstring const> items); | ||
|
||
// IIterable<hstring> | ||
winrt::Windows::Foundation::Collections::IIterator<hstring> First() const; | ||
|
||
private: | ||
winrt::Windows::Foundation::Collections::IVector<hstring> m_innerVector{ single_threaded_vector<hstring>() }; | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we care if there are embedded nulls? Same question for the Commit button text.