Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Pass doc into validator ui using url #20391

Merged
merged 3 commits into from
Jan 30, 2019
Merged

✨Pass doc into validator ui using url #20391

merged 3 commits into from
Jan 30, 2019

Conversation

calebcordry
Copy link
Member

We have a partner that would like the ability to construct a link to the validator.ampproject.org page whereby they can send the document to be validated in the url.

This introduces that functionality by passing the document string as a base64 encoded query param, which is then inserted into the text area to be validated.

Due to the btoa unicode problem, I opted to use the solution given on this mdn page. The function used for encoding:

// ucs-2 string to base64 encoded ascii
function utoa(str) {
    return window.btoa(unescape(encodeURIComponent(str)));
}

If you would like an encoded param to use there is one in this gist

This is pending an internal review from the Google security team.


// Extract queryParams from url and return object.
function getSearchParams() {
const {search} = window.location;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we use fragment? since we have #htmlFormat=AMP4ADS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, one other reason to use fragment is so that no data is transfer to the server. that in general prevent any potential privacy related issue (PII in the data etc).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@calebcordry
Copy link
Member Author

Updated to use fragment. PTAL @honeybadgerdontcare @lannka

const incomingDocStr = getIncomingDoc(params);
if (incomingDocStr) {
editor.setEditorValue(incomingDocStr);
const format = params['htmlFormat'] || 'AMP4ADS';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the intent is to use this for AMP4ADS but right now the default when not specified in the WebUI is AMP and I'd like to stick to that for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I set the default to AMP we will just need to tell partners to include htmlFormat=AMP4ADS

@honeybadgerdontcare
Copy link
Contributor

Once this is merged and also live in prod, lets document it in the readme

@calebcordry calebcordry merged commit 6edaef0 into ampproject:master Jan 30, 2019
@calebcordry calebcordry deleted the validator-link branch January 30, 2019 18:42
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* read param

* use fragment

* set default to amp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants