Skip to content

Commit

Permalink
fix scheme name resolution, and schema load on WSL (#5327)
Browse files Browse the repository at this point in the history
This PR fixes the scheme resolution bug outlined in #5326

The approach is as follows:

* In [SchemeManager.cs], find the first scheme parser that actually
  successfully parses the scheme, as opposed to the existing code, which
  finds the first scheme parser which _says it can parse the scheme_, as
  that logic spuriously returns `true` currently. 
* In [XmlSchemeParser.cs] and [JsonParser.cs], ensure that the contents
  of the file are read and the contents passed to XmlDocument.LoadXXX,
  as this fails with an UriException on WSL otherwise.
* Remove `CanParse` as it is superfluous. The check for a valid scheme
  parser should not just check an extension but also if the file exists
  - this is best done by the `ParseScheme` function as it already
  returns null on failure.
* Add `FileExtension` to the interface because we need it lifted now.

Closes #5326
  • Loading branch information
johnazariah authored Jul 1, 2020
1 parent 44e80d4 commit 436fac6
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 492 deletions.
3 changes: 1 addition & 2 deletions src/tools/ColorTool/ColorTool/SchemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public static void PrintSchemes()
public static ColorScheme GetScheme(string schemeName, bool reportErrors = false)
{
return GetParsers()
.Where(parser => parser.CanParse(schemeName))
.Select(parser => parser.ParseScheme(schemeName, reportErrors))
.FirstOrDefault();
.FirstOrDefault(x => x != null);
}

public static IEnumerable<ISchemeParser> GetParsers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ColorTool.SchemeParsers
interface ISchemeParser
{
string Name { get; }
bool CanParse(string schemeName);
string FileExtension { get; }
ColorScheme ParseScheme(string schemeName, bool reportErrors = false);
}
}
Loading

0 comments on commit 436fac6

Please sign in to comment.