OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. | 3 * Copyright (C) 2009 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "platform/clipboard/ClipboardUtilities.h" | 28 #include "platform/clipboard/ClipboardUtilities.h" |
29 | 29 |
30 #include "wtf/text/WTFString.h" | 30 #include "wtf/text/WTFString.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace blink { |
33 | 33 |
34 // On POSIX systems, the typical filename length limit is 255 character units. H
FS+'s limit is | 34 // On POSIX systems, the typical filename length limit is 255 character units. H
FS+'s limit is |
35 // actually 255 Unicode characters using Apple's modification of Normzliation Fo
rm D, but the | 35 // actually 255 Unicode characters using Apple's modification of Normzliation Fo
rm D, but the |
36 // differences aren't really worth dealing with here. | 36 // differences aren't really worth dealing with here. |
37 static const unsigned maxFilenameLength = 255; | 37 static const unsigned maxFilenameLength = 255; |
38 | 38 |
39 static bool isInvalidFileCharacter(UChar c) | 39 static bool isInvalidFileCharacter(UChar c) |
40 { | 40 { |
41 // HFS+ disallows '/' and Linux systems also disallow null. For sanity's sak
e we'll also | 41 // HFS+ disallows '/' and Linux systems also disallow null. For sanity's sak
e we'll also |
42 // disallow control characters. | 42 // disallow control characters. |
43 return c < ' ' || c == 0x7F || c == '/'; | 43 return c < ' ' || c == 0x7F || c == '/'; |
44 } | 44 } |
45 | 45 |
46 void validateFilename(String& name, String& extension) | 46 void validateFilename(String& name, String& extension) |
47 { | 47 { |
48 // Remove any invalid file system characters, especially "/". | 48 // Remove any invalid file system characters, especially "/". |
49 name = name.removeCharacters(&isInvalidFileCharacter); | 49 name = name.removeCharacters(&isInvalidFileCharacter); |
50 extension = extension.removeCharacters(&isInvalidFileCharacter); | 50 extension = extension.removeCharacters(&isInvalidFileCharacter); |
51 | 51 |
52 // Remove a ridiculously-long extension. | 52 // Remove a ridiculously-long extension. |
53 if (extension.length() >= maxFilenameLength) | 53 if (extension.length() >= maxFilenameLength) |
54 extension = String(); | 54 extension = String(); |
55 | 55 |
56 // Truncate an overly-long filename, reserving one character for a dot. | 56 // Truncate an overly-long filename, reserving one character for a dot. |
57 name.truncate(maxFilenameLength - extension.length() - 1); | 57 name.truncate(maxFilenameLength - extension.length() - 1); |
58 } | 58 } |
59 | 59 |
60 } // namespace WebCore | 60 } // namespace blink |
OLD | NEW |