|
16 | 16 | public class FilenameConstraintValidator implements ConstraintValidator<FilenameValid, String> { |
17 | 17 | // Used a RegEx from Internet to check the strict one (Old Windows) to see if all matches. |
18 | 18 | private final Pattern pattern = Pattern.compile( |
19 | | - "# Match a valid Windows filename (unspecified file system).\n" + |
20 | | - "^ # Anchor to start of string.\n" + |
21 | | - "(?! # Assert filename is not: CON, PRN,\n" + |
22 | | - " (?: # AUX, NUL, COM1, COM2, COM3, COM4,\n" + |
23 | | - " CON|PRN|AUX|NUL| # COM5, COM6, COM7, COM8, COM9,\n" + |
24 | | - " COM[1-9]|LPT[1-9] # LPT1, LPT2, LPT3, LPT4, LPT5,\n" + |
25 | | - " ) # LPT6, LPT7, LPT8, and LPT9...\n" + |
26 | | - " (?:\\.[^.]*)? # followed by optional extension\n" + |
27 | | - " $ # and end of string\n" + |
28 | | - ") # End negative lookahead assertion.\n" + |
29 | | - "[^<>:\"/\\\\|?*\\x00-\\x1F]* # Zero or more valid filename chars.\n" + |
30 | | - "[^<>:\"/\\\\|?*\\x00-\\x1F\\ .] # Last char is not a space or dot.\n" + |
31 | | - "$ # Anchor to end of string.", |
| 19 | + """ |
| 20 | + # Match a valid Windows filename (unspecified file system). |
| 21 | + ^# Anchor to start of string. |
| 22 | + (?!# Assert filename is not: |
| 23 | + (?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])# CON,PRN,AUX,NUL,COM1-9,LPT1-9 |
| 24 | + (?:\\.[^.]*)?# followed by optional extension |
| 25 | + $)# End negative lookahead assertion. |
| 26 | + [^<>:"/\\\\|?*\\x00-\\x1F]*# Zero or more valid filename chars. |
| 27 | + [^<>:"/\\\\|?*\\x00-\\x1F .]$# Last char is not a space or dot. |
| 28 | + """, |
32 | 29 | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS); |
33 | 30 |
|
34 | 31 | @Override |
|
0 commit comments