diff --git a/validator/webui/@polymer/webui-mainpage/webui-mainpage.html b/validator/webui/@polymer/webui-mainpage/webui-mainpage.html index 3782f97198a6..00b225de19b9 100644 --- a/validator/webui/@polymer/webui-mainpage/webui-mainpage.html +++ b/validator/webui/@polymer/webui-mainpage/webui-mainpage.html @@ -298,9 +298,17 @@ // Interprets the parameters after the '#' in the URL. var params = getLocationHashParams(); + // Extracts the code to be validated if sent as a query param. + const incomingDocStr = getIncomingDoc(params); + if (incomingDocStr) { + editor.setEditorValue(incomingDocStr); + const format = params['htmlFormat'] || 'AMP'; + urlForm.setHtmlFormat(format) + } + // If #url= was provided, load it, otherwise, start with the // minimum valid AMP document. - if (params.hasOwnProperty('url') && params['url']) { + else if (params.hasOwnProperty('url') && params['url']) { this.$.urlForm.setURLAndValidate(params['url']); // If filter= was provided, filter error-list. if (params.hasOwnProperty('filter') && params['filter']) { diff --git a/validator/webui/serve-standalone.go b/validator/webui/serve-standalone.go index ab8bb6ab4d70..387a0d46459e 100644 --- a/validator/webui/serve-standalone.go +++ b/validator/webui/serve-standalone.go @@ -46,7 +46,7 @@ func handler(w http.ResponseWriter, r *http.Request) { // // Handle '/'. // - if r.RequestURI == "/" { + if r.URL.Path == "/" { bytes, err := ioutil.ReadFile("index.html") if err != nil { http.Error(w, "File not found.", http.StatusNotFound) diff --git a/validator/webui/webui.js b/validator/webui/webui.js index 93b97fb17f6c..33753a0c3749 100644 --- a/validator/webui/webui.js +++ b/validator/webui/webui.js @@ -15,6 +15,8 @@ * limitations under the license. */ +const DOC_INPUT_ATTR = 'doc'; + // Extracts a dictionary of parameters from window.location.hash. function getLocationHashParams() { const paramStrings = window.location.hash.substr(1).split('&'); @@ -46,3 +48,17 @@ function setLocationHashParams(params) { } window.location.hash = out.join('&'); } + +// Base64 encoded ascii to ucs-2 string. +function atou(str) { + return decodeURIComponent(escape(atob(str))); +} + +// Get query param that may contain an encoded document to be validated. Decode +// and return. +function getIncomingDoc(params) { + if (!params || !params[DOC_INPUT_ATTR]) { + return null; + } + return atou(params[DOC_INPUT_ATTR]); +}