MCPcopy Create free account
hub / github.com/ampproject/amphtml / validateString

Function validateString

validator/cpp/engine/wasm/validator.js:98–117  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

96 * @return {Object!} Validation Result (status and errors)
97 */
98function 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.

Callers 1

validateUrlAndLogFunction · 0.85

Calls 2

getMethod · 0.45

Tested by

no test coverage detected