[FFmpeg-devel] [PATCH][RFC] ffprobe: Consider the chosen separator when doing CSV escaping

Alexander Strasser eclipse7 at gmx.net
Tue Sep 18 23:26:42 CEST 2012


Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---

  Just a first step. More stuff like escaping key fields and checking the
separator does not collide with other meta characters would be the ones I
can think ATM.

  But I wanted comments on this ideas first. As the discussion might lead
to develop things in a different direction.

  Also I am curious if the code will work with all compilers we currently
support. AFAICT non-const aggregate initialization is not allowed by C89.
But it is trivial to rewrite anyway.

 ffprobe.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ffprobe.c b/ffprobe.c
index aad5d90..09be445 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -566,7 +566,8 @@ static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep,
  */
 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
 {
-    int needs_quoting = !!src[strcspn(src, "\",\n\r")];
+    char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
+    int needs_quoting = !!src[strcspn(src, meta_chars)];
 
     if (needs_quoting)
         av_bprint_chars(dst, '\"', 1);
-- 
1.7.10.2.552.gaa3bb87


More information about the ffmpeg-devel mailing list