license author lwe google import * as csp from './csp' ; unrestricted export class CspParser { csp : csp . Csp ; param unparsedCsp constructor ( unparsedCsp ) { /**
         * Parsed CSP
         */ this . csp = new csp . Csp ( ) ; this . parse ( unparsedCsp ) ; } param unparsedCsp parse ( unparsedCsp ) { this . csp = new csp . Csp ( ) ; const directiveTokens = unparsedCsp . split ( ';' ) ; for ( let i = 0 ; i < directiveTokens . length ; i ++ ) { const directiveToken = directiveTokens [ i ] . trim ( ) ; const directiveParts = directiveToken . match ( /\S+/g ) ; if ( Array . isArray ( directiveParts ) ) { const directiveName = directiveParts [ 0 ] . toLowerCase ( ) ; if ( directiveName in this . csp . directives ) { continue ; } if ( ! csp . isDirective ( directiveName ) ) { } const directiveValues = [ ] ; for ( let directiveValue , j = 1 ; ( directiveValue = directiveParts [ j ] ) ; j ++ ) { directiveValue = normalizeDirectiveValue ( directiveValue ) ; if ( ! directiveValues . includes ( directiveValue ) ) { directiveValues . push ( directiveValue ) ; } } this . csp . directives [ directiveName ] = directiveValues ; } } return this . csp ; } } param directiveValue return function normalizeDirectiveValue ( directiveValue ) { directiveValue = directiveValue . trim ( ) ; const directiveValueLower = directiveValue . toLowerCase ( ) ; if ( csp . isKeyword ( directiveValueLower ) || csp . isUrlScheme ( directiveValue ) ) { return directiveValueLower ; } return directiveValue ; } export const TEST_ONLY = { normalizeDirectiveValue } ;