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

Invalid language parameter is treated as all languages #1246

Closed
2 of 3 tasks
mikaelnet opened this issue Oct 7, 2021 · 2 comments
Closed
2 of 3 tasks

Invalid language parameter is treated as all languages #1246

mikaelnet opened this issue Oct 7, 2021 · 2 comments
Assignees
Labels
🤩-release-highlight Exciting change that should be highlighted in the release notes and celebrated by SPE fans. 🐞 bug Oops! Sorry for the inconvenience. impact-behaviour-change Nothing to be worried about. Now even better than before!
Milestone

Comments

@mikaelnet
Copy link

Expected Behavior

If I load item(s) via Get-Item, Get-ChildItem etc. and accidentally provide an incorrect language parameter, I'd like SPE to give an error message and/or not return any results. Maybe the current behavior is by design, and I understand if this fix/change isn't worth doing. If an invalid language is provided to the -Language parameter, it is silently accepted and is treated as * (any language).

Actual Behavior

If I provide an invalid language, it is treated as * or all languages. So if I want to perform an action on a set of items on a specific language layer and mistype the language parameter, the action will be performed on all languages. So basically, this problem only occurs when there is a typo/error in the provided script, but the consequence can be quite sever.

Steps to Reproduce the Problem

I've tested this on 6.0 and 6.1.1, but haven't yet been able to test this on the latest version.
To reproduce the problem, an item with more than one language layer is required.

Get-Item -Path 'master:/sitecore/content/home -Language 'some-typo' | Format-Table will return all language versions of that item, basically the same as providing -Language *. I'd expect zero versions to be returned and/or that it gives an error. Right now I've tested this on Get-Item and Get-ChildItem, but briefly browsing the SPE code I assume this applies to more cmdlets.

Browsing the code, it seems like the handling of LanguageWildcardPatterns in BaseItemCommand.cs could be the source of this, but I may be completely wrong. A wild guess of the root cause could be the WildcardUtils.GetWildcardPattern returning * if name is null or empty. Is it as simple as name becoming null/empty if the input value cannot be parsed into a CultureInfo object?

Sample tests:

  • Get-Item ... -Language en,* returns "en" plus all languages, so the "en" version is listed twice. Makes sense.
  • Get-Item ... -Language en,en-US,* returns "en", "en-US" plus all languages, so the "en" and "en-US" versions are listed twice. Basically the same as above. Makes sense.
  • Get-Item ... -Language foo where foo is not a registered culture, returns the same as *. This feels scary.
  • Get-Item ... -Language en,foo where foo is not a registered culture, returns exactly the same as en,*. This feels scary.
  • Get-Item ... without the language parameter returns data on the context language as expected.

So basically, when a provided language string cannot be parsed into a culture, it treats it as a wildcard.

  • Tested issue with clean install of Sitecore and the latest available version of SPE.
  • Asked questions on the Sitecore Slack Chat channel.
  • Reviewed questions and answers on the Sitecore Stack Exchange.
@michaellwest
Copy link
Member

From what I can see, there is a call to LanguageManager.GetLanguage("foo") which ultimately returns an array of one item with a null value... SPE turns that into the wildcard *.

I would expect a language unknown to the LanguageManager to result in no items for that language.

@michaellwest
Copy link
Member

Write-Host 'Good language + wildcard: Get-Item -Path "." -Language "en",*'
Get-Item -Path "." -Language "en",* | Format-Table

Write-Host 'Missing language: Get-Item -Path "." -Language "foo"'
Get-Item -Path "." -Language "foo" | Format-Table

Write-Host 'Good and bad language: Get-Item -Path "." -Language "en","foo"'
Get-Item -Path "." -Language "en","foo" | Format-Table

Write-Host 'No language: Get-Item -Path "."'
Get-Item -Path "." | Format-Table
Good language + wildcard: Get-Item -Path "." -Language "en",*

Name Children Language Version Id                                     TemplateName
---- -------- -------- ------- --                                     ------------
Home False    en       2       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Home False    en       2       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Home False    en-CA    2       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item


Missing language: Get-Item -Path "." -Language "foo"
Good and bad language: Get-Item -Path "." -Language "en","foo"

Name Children Language Version Id                                     TemplateName
---- -------- -------- ------- --                                     ------------
Home False    en       2       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item


No language: Get-Item -Path "."

Name Children Language Version Id                                     TemplateName
---- -------- -------- ------- --                                     ------------
Home False    en       2       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item



michaellwest added a commit that referenced this issue Mar 11, 2022
@michaellwest michaellwest self-assigned this Mar 11, 2022
@michaellwest michaellwest added 🐞 bug Oops! Sorry for the inconvenience. impact-behaviour-change Nothing to be worried about. Now even better than before! 🤩-release-highlight Exciting change that should be highlighted in the release notes and celebrated by SPE fans. labels Mar 11, 2022
@michaellwest michaellwest added this to the 6.4 milestone Mar 11, 2022
michaellwest added a commit that referenced this issue Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤩-release-highlight Exciting change that should be highlighted in the release notes and celebrated by SPE fans. 🐞 bug Oops! Sorry for the inconvenience. impact-behaviour-change Nothing to be worried about. Now even better than before!
Projects
None yet
Development

No branches or pull requests

2 participants