1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "config.h" 6 #include "platform/network/ContentSecurityPolicyParsers.h" 7 8 #include "wtf/ASCIICType.h" 9 10 namespace WebCore { 11 isCSPDirectiveNameCharacter(UChar c)12bool isCSPDirectiveNameCharacter(UChar c) 13 { 14 return isASCIIAlphanumeric(c) || c == '-'; 15 } 16 isCSPDirectiveValueCharacter(UChar c)17bool isCSPDirectiveValueCharacter(UChar c) 18 { 19 return isASCIISpace(c) || (c >= 0x21 && c <= 0x7e); // Whitespace + VCHAR 20 } 21 22 // Only checks for general Base64 encoded chars, not '=' chars since '=' is 23 // positional and may only appear at the end of a Base64 encoded string. isBase64EncodedCharacter(UChar c)24bool isBase64EncodedCharacter(UChar c) 25 { 26 return isASCIIAlphanumeric(c) || c == '+' || c == '/'; 27 } 28 isNonceCharacter(UChar c)29bool isNonceCharacter(UChar c) 30 { 31 return isBase64EncodedCharacter(c) || c == '='; 32 } 33 isSourceCharacter(UChar c)34bool isSourceCharacter(UChar c) 35 { 36 return !isASCIISpace(c); 37 } 38 isPathComponentCharacter(UChar c)39bool isPathComponentCharacter(UChar c) 40 { 41 return c != '?' && c != '#'; 42 } 43 isHostCharacter(UChar c)44bool isHostCharacter(UChar c) 45 { 46 return isASCIIAlphanumeric(c) || c == '-'; 47 } 48 isSchemeContinuationCharacter(UChar c)49bool isSchemeContinuationCharacter(UChar c) 50 { 51 return isASCIIAlphanumeric(c) || c == '+' || c == '-' || c == '.'; 52 } 53 isNotASCIISpace(UChar c)54bool isNotASCIISpace(UChar c) 55 { 56 return !isASCIISpace(c); 57 } 58 isNotColonOrSlash(UChar c)59bool isNotColonOrSlash(UChar c) 60 { 61 return c != ':' && c != '/'; 62 } 63 isMediaTypeCharacter(UChar c)64bool isMediaTypeCharacter(UChar c) 65 { 66 return !isASCIISpace(c) && c != '/'; 67 } 68 69 } // namespace 70