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 12 matching lines...) Expand all Loading... |
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 "platform/clipboard/ClipboardUtilities.h" | 27 #include "platform/clipboard/ClipboardUtilities.h" |
28 | 28 |
29 #include "wtf/text/WTFString.h" | 29 #include "wtf/text/WTFString.h" |
30 | 30 |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 // On POSIX systems, the typical filename length limit is 255 character units. H
FS+'s limit is | 33 // On POSIX systems, the typical filename length limit is 255 character units. |
34 // actually 255 Unicode characters using Apple's modification of Normzliation Fo
rm D, but the | 34 // HFS+'s limit is actually 255 Unicode characters using Apple's modification of |
35 // differences aren't really worth dealing with here. | 35 // Normzliation Form D, but the differences aren't really worth dealing with |
| 36 // here. |
36 static const unsigned maxFilenameLength = 255; | 37 static const unsigned maxFilenameLength = 255; |
37 | 38 |
38 static bool isInvalidFileCharacter(UChar c) { | 39 static bool isInvalidFileCharacter(UChar c) { |
39 // HFS+ disallows '/' and Linux systems also disallow null. For sanity's sake
we'll also | 40 // HFS+ disallows '/' and Linux systems also disallow null. For sanity's sake |
40 // disallow control characters. | 41 // we'll also disallow control characters. |
41 return c < ' ' || c == 0x7F || c == '/'; | 42 return c < ' ' || c == 0x7F || c == '/'; |
42 } | 43 } |
43 | 44 |
44 void validateFilename(String& name, String& extension) { | 45 void validateFilename(String& name, String& extension) { |
45 // Remove any invalid file system characters, especially "/". | 46 // Remove any invalid file system characters, especially "/". |
46 name = name.removeCharacters(&isInvalidFileCharacter); | 47 name = name.removeCharacters(&isInvalidFileCharacter); |
47 extension = extension.removeCharacters(&isInvalidFileCharacter); | 48 extension = extension.removeCharacters(&isInvalidFileCharacter); |
48 | 49 |
49 // Remove a ridiculously-long extension. | 50 // Remove a ridiculously-long extension. |
50 if (extension.length() >= maxFilenameLength) | 51 if (extension.length() >= maxFilenameLength) |
51 extension = String(); | 52 extension = String(); |
52 | 53 |
53 // Truncate an overly-long filename, reserving one character for a dot. | 54 // Truncate an overly-long filename, reserving one character for a dot. |
54 name.truncate(maxFilenameLength - extension.length() - 1); | 55 name.truncate(maxFilenameLength - extension.length() - 1); |
55 } | 56 } |
56 | 57 |
57 } // namespace blink | 58 } // namespace blink |
OLD | NEW |