Skip to content

Commit

Permalink
Better handling for swinfo dep node_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 28, 2023
1 parent b916779 commit 5d1b8b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
19 changes: 7 additions & 12 deletions Core/Types/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,28 @@ public static class Identifier
/// </summary>
public static readonly Regex ValidIdentifierPattern = new Regex(
@"^[A-Za-z0-9][A-Za-z0-9-]+$",
RegexOptions.Compiled
);
RegexOptions.Compiled);

/// <summary>
/// Turn a possibly invalid identifier string into a valid identifier string
/// </summary>
/// <param name="ident">String that we want to turn into an identifier</param>
/// <param name="replacement">String that should be inserted in place of characters that aren't allowed</param>
/// <returns>
/// ident with any non-alphanumeric characters removed from the start so it
/// begins with alphanumeric, and any remaining non-alphanumeric characters
/// replaced with dashes so the overall string format is preserved
/// </returns>
public static string Sanitize(string ident)
{
return InvalidIdentifierCharacterPattern.Replace(
public static string Sanitize(string ident, string replacement = "-")
=> InvalidIdentifierCharacterPattern.Replace(
InvalidPrefixPattern.Replace(ident, ""),
"-"
);
}
replacement);

private static readonly Regex InvalidIdentifierCharacterPattern = new Regex(
@"[^A-Za-z0-9-]",
RegexOptions.Compiled
);
RegexOptions.Compiled);
private static readonly Regex InvalidPrefixPattern = new Regex(
@"^[^A-Za-z0-9]+",
RegexOptions.Compiled
);
RegexOptions.Compiled);
}
}
3 changes: 2 additions & 1 deletion Netkan/Transformers/SpaceWarpInfoTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
.Select(dep => dep.id)
.Where(depId => !moduleDeps.Contains(
// Remove up to last period
depId.Substring(depId.LastIndexOf('.') + 1),
Identifier.Sanitize(
depId.Substring(depId.LastIndexOf('.') + 1), ""),
// Case insensitive
StringComparer.InvariantCultureIgnoreCase))
.ToList();
Expand Down

0 comments on commit 5d1b8b8

Please sign in to comment.