Skip to content

Commit

Permalink
Fix LT-22041: Handle null license in case of bad image metadata
Browse files Browse the repository at this point in the history
* This work also exposed incorrect logic for missing licenses
  on Webonary uplaod
  • Loading branch information
jasonleenaylor committed Feb 4, 2025
1 parent 430b73c commit 9dc5dfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Src/xWorks/DictConfigModelExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.Linq;
using SIL.Reporting;
using SIL.Windows.Forms.ClearShare;

Expand Down Expand Up @@ -30,8 +31,14 @@ public static string CopyrightAndLicense(this LCModel.ICmPicture picture)
}
// As of 2023.07, the only implementation that actually uses the language list is CustomLicense w/o custom text,
// which our UI seems to prevent users from creating.
var license = metadata.License.GetMinimalFormForCredits(new[] { "en" }, out _);
return string.IsNullOrEmpty(license) ? metadata.ShortCopyrightNotice : string.Join(", ", metadata.ShortCopyrightNotice, license);
var license = metadata.License?.GetMinimalFormForCredits(new[] { "en" }, out _);
if (string.IsNullOrEmpty(metadata.CopyrightNotice) && string.IsNullOrEmpty(license))
return null;
// We want the short copyright notice, but it isn't safe to ask for if CopyrightNotice is null
var copyright = string.IsNullOrEmpty(metadata.CopyrightNotice)
? metadata.ShortCopyrightNotice
: string.Empty;
return string.Join(", ", new[] { copyright, license }.Where(txt => !string.IsNullOrEmpty(txt)));
}

private static Metadata MetadataFromFile(this LCModel.ICmPicture picture)
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/UploadToWebonaryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ private bool IsFileLicenseValidForUpload(string path)
if (imageExtensions.Any(path.ToLowerInvariant().EndsWith))
{
var metaData = Metadata.FromFile(path);
if (metaData == null || !metaData.IsMinimallyComplete || !metaData.IsLicenseNotSet)
if (metaData == null || !metaData.IsMinimallyComplete || metaData.IsLicenseNotSet)
{
return false;
}
Expand Down

0 comments on commit 9dc5dfe

Please sign in to comment.