* Validates a document input as a string. * * @param {string} input * @param {string=} opt_htmlFormat the allowed format; defaults to 'AMP'. * @return {Object!} Validation Result (status and errors)
(input, opt_htmlFormat)
| 96 | * @return {Object!} Validation Result (status and errors) |
| 97 | */ |
| 98 | function validateString(input, opt_htmlFormat) { |
| 99 | let htmlFormat = 'AMP'; |
| 100 | if (opt_htmlFormat) { |
| 101 | htmlFormat = opt_htmlFormat.toUpperCase(); |
| 102 | } |
| 103 | asserts.assertExists(wasmModule, `WebAssembly is uninitialized`); |
| 104 | const resultBase64 = |
| 105 | wasmModule.validateString(input, htmlFormat, /*maxErrors=*/ -1); |
| 106 | const resultJspb = ValidationResult.deserializeBinary(resultBase64); |
| 107 | const resultObject = resultJspb.toObject(); |
| 108 | resultObject.errors = resultJspb.getErrorsList().map((errorJspb) => { |
| 109 | const errorObject = stringifyValidationErrorFields(errorJspb.toObject()); |
| 110 | errorObject[PB_BASE64] = |
| 111 | base64.encodeByteArray(errorJspb.serializeBinary()); |
| 112 | return errorObject; |
| 113 | }); |
| 114 | resultObject.status = STATUS.nameByNumber.get(resultObject.status); |
| 115 | resultObject[PB_BASE64] = resultBase64; |
| 116 | return resultObject; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Renders the error message for a single error. |
no test coverage detected