From da453487515e40f661a393551501f38665704332 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Thu, 29 Aug 2013 21:55:59 +0000 Subject: [PATCH] Sanitize file name --- wp2git.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wp2git.d b/wp2git.d index b631ce1..7f957c4 100644 --- a/wp2git.d +++ b/wp2git.d @@ -66,7 +66,7 @@ int main(string[] args) "committer " ~ committer ~ " <" ~ committer ~ "@" ~ language ~ ".wikipedia.org> " ~ ISO8601toRFC2822(child["timestamp"].text) ~ "\n" ~ "data " ~ to!string(summary.length) ~ "\n" ~ summary ~ "\n" ~ - "M 644 inline " ~ name ~ ".txt\n" ~ + "M 644 inline " ~ sanitizeFn(name) ~ ".txt\n" ~ "data " ~ to!string(text.length) ~ "\n" ~ text ~ "\n" ~ "\n"; @@ -94,3 +94,13 @@ string ISO8601toRFC2822(string s) // Feb 6 11:22:18 2007 -0500 return monthNames[.to!int(s[5..7])-1] ~ " " ~ s[8..10] ~ " " ~ s[11..13] ~ ":" ~ s[14..16] ~ ":" ~ s[17..19] ~ " " ~ s[0..4] ~ " +0000"; } + +string sanitizeFn(string s) +{ + static const string forbidden = `?*<>|:\/"`; + auto copy = s.dup; + foreach (ref c; copy) + if (forbidden.indexOf(c) >= 0) + c = '_'; + return assumeUnique(copy); +}