Skip to content

Commit

Permalink
Only escape backslashes, single quotes, and newlines when writing ffm…
Browse files Browse the repository at this point in the history
…etadata (#1161)

* Only escape backslashes and single quotes in SanitizeKeyValue

this documentation is correct:
https://ffmpeg.org/ffmpeg-utils.html

this is outdated:
https://ffmpeg.org/ffmpeg-formats.html#metadata

* Return LINE_FEED to SanitizeKeyValue

* Add comment to SanitizeKeyValue =;# do not need to be escaped
  • Loading branch information
superbonaci authored Jul 24, 2024
1 parent 03264b0 commit 4c65eb8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions TwitchDownloaderCore/Tools/FfmpegMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,22 @@ private static async Task SerializeChapters(StreamWriter sw, IEnumerable<VideoMo
}
}

// https://trac.ffmpeg.org/ticket/11096 The Ffmpeg documentation is outdated and =;# do not need to be escaped.
private static string SanitizeKeyValue(string str)
{
if (string.IsNullOrWhiteSpace(str))
{
return str;
}

if (str.AsSpan().IndexOfAny(@$"=;#\{LINE_FEED}") == -1)
if (str.AsSpan().IndexOfAny(@$"\'{LINE_FEED}") == -1)
{
return str;
}

return new StringBuilder(str)
.Replace("=", @"\=")
.Replace(";", @"\;")
.Replace("#", @"\#")
.Replace(@"\", @"\\")
.Replace("'", @"\'")
.Replace(LINE_FEED, $@"\{LINE_FEED}")
.ToString();
}
Expand Down

0 comments on commit 4c65eb8

Please sign in to comment.