Skip to content

Commit

Permalink
Fix incorrect alternative images being used
Browse files Browse the repository at this point in the history
With embedded resources:

gtc-solution.png
gtc-solution@2x.png
gtc-solution~contrast.png

gtc-solution-filter.png
gtc-solution-filter@2x.png
gtc-solution-filter~contrast.png

The ParseImageHints method would find an image match when the
baseName was gtc-solution and the fileName was gtc-solution@2x.png
or gtc-solution~contrast.png. The problem was the original check
used fileName.StartsWith(baseName) which allowed this mismatch.
Changing the check to compare the fileName before the first
delimiter found with the baseName avoids an incorrect image being
used.
  • Loading branch information
mrward committed Feb 16, 2021
1 parent 6221704 commit e33ea10
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Xwt/Xwt.Drawing/Image.cs
Expand Up @@ -252,7 +252,7 @@ static bool ParseImageHints (string baseName, string fileName, string ext, out i
tags = ImageTagSet.Empty;
var firstDelimiter = fileName.IndexOfAny (tagDelimiters);

if (firstDelimiter <= 0 || fileName.Length <= baseName.Length + 1 || !fileName.StartsWith (baseName, StringComparison.Ordinal))
if (firstDelimiter <= 0 || fileName.Length <= baseName.Length + 1 || !fileName.Substring(0, firstDelimiter).Equals(baseName, StringComparison.Ordinal))
return false;

fileName = fileName.Substring (0, fileName.Length - ext.Length);
Expand Down

0 comments on commit e33ea10

Please sign in to comment.