From e829f46782e6b98491c9c3c70159af2ab1d25da6 Mon Sep 17 00:00:00 2001 From: Collin Barrett Date: Tue, 30 Jan 2018 18:17:50 -0600 Subject: [PATCH] strip single backslash from end of rule throws MySQL exception since it thinks it is escaping closing single quote. may be temporary, should re-evaluate. --- .../Services/ScrapeService.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/FilterLists.Services/Services/ScrapeService.cs b/src/FilterLists.Services/Services/ScrapeService.cs index ef2073058..33e155a57 100644 --- a/src/FilterLists.Services/Services/ScrapeService.cs +++ b/src/FilterLists.Services/Services/ScrapeService.cs @@ -70,10 +70,7 @@ private static async Task GetHttpResponseMessageContent(string url) private async Task SaveSnapshots(IEnumerable snapshots) { - foreach (var snapshot in snapshots) - { - await AddOrUpdateRules(snapshot); - } + foreach (var snapshot in snapshots) await AddOrUpdateRules(snapshot); } private async Task AddOrUpdateRules(Snapshot snapshot) @@ -126,13 +123,26 @@ private class FilterListViewUrlDto private class Snapshot { - public string Content { - set => RawRules = value?.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); + public string Content + { + set + { + if (value == null) return; + var rawRules = value.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries); + for (var i = 0; i < rawRules.Length; i++) + rawRules[i] = TrimSingleBackslashFromEnd(rawRules[i]); + RawRules = rawRules; + } } public int FilterListId { get; set; } public string[] RawRules { get; private set; } + + private static string TrimSingleBackslashFromEnd(string rule) + { + return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule; + } } } } \ No newline at end of file