Prevent NREs for null text (#8418)

When the text we are localizing is null (which potentially happens when localizing dynamic content), it could result in a null parent translation, which would throw when used as "basis" for comparisons.
This commit is contained in:
Matteo Piovanelli 2020-09-21 12:10:31 +02:00 committed by GitHub
parent 0d3f3ed9f3
commit 70c04a9a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,6 +51,7 @@ namespace Orchard.Localization.Services {
public FormatForScope GetLocalizedString(IEnumerable<string> scopes, string text, string cultureName) {
var culture = LoadCulture(cultureName);
text = text ?? string.Empty; // prevent NREs with this string
foreach (var scope in scopes) {
string scopedKey = (scope + "|" + text).ToLowerInvariant();
if (culture.Translations.ContainsKey(scopedKey)) {