Sanitize file name
This commit is contained in:
parent
3536d47f5d
commit
da45348751
12
wp2git.d
12
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue