mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
drop comments from rules
This commit is contained in:
parent
ad3b476c0e
commit
ed30ebf6c7
1 changed files with 14 additions and 7 deletions
|
|
@ -2,14 +2,14 @@
|
|||
{
|
||||
public static class RawRuleLinterExtensions
|
||||
{
|
||||
//TODO: resolve issues and/or track dropped rules
|
||||
public static string LintStringForMySql(this string rule)
|
||||
{
|
||||
rule = rule.TrimLeadingAndTrailingWhitespace();
|
||||
rule = rule.DropIfEmpty();
|
||||
rule = rule.TrimSingleBackslashFromEnd();
|
||||
rule = rule.DropIfContainsBackslashSingleQuote();
|
||||
rule = rule.DropIfComment();
|
||||
rule = rule.DropIfTooLong();
|
||||
rule = rule.DropIfContainsBackslashSingleQuote();
|
||||
rule = rule.TrimSingleBackslashFromEnd();
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
|
@ -24,13 +24,18 @@ private static string DropIfEmpty(this string rule)
|
|||
return rule == "" ? null : rule;
|
||||
}
|
||||
|
||||
private static string TrimSingleBackslashFromEnd(this string rule)
|
||||
private static string DropIfComment(this string rule)
|
||||
{
|
||||
if (rule != null)
|
||||
return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule;
|
||||
return rule.StartsWith(@"!") && !rule.StartsWith(@"!#") ? null : rule;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string DropIfTooLong(this string rule)
|
||||
{
|
||||
return rule?.Length > 8192 ? null : rule;
|
||||
}
|
||||
|
||||
private static string DropIfContainsBackslashSingleQuote(this string rule)
|
||||
{
|
||||
if (rule != null)
|
||||
|
|
@ -38,9 +43,11 @@ private static string DropIfContainsBackslashSingleQuote(this string rule)
|
|||
return null;
|
||||
}
|
||||
|
||||
private static string DropIfTooLong(this string rule)
|
||||
private static string TrimSingleBackslashFromEnd(this string rule)
|
||||
{
|
||||
return rule?.Length > 8192 ? null : rule;
|
||||
if (rule != null)
|
||||
return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue