amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-social-share type attribute need more validation

Open muxin opened this issue 10 years ago • 4 comments

Error: Failed to execute 'add' on 'DOMTokenList': The token provided ('amp-social-share-whats app') contains HTML space characters, which are not valid in tokens.
    at Error (native)
    at AmpSocialShare.buildCallback (http://localhost:8000/dist/v0/amp-social-share-0.1.max.js:168:28)
    at amp-social-share.ElementProto.build (http://localhost:8000/dist/amp.js:4181:28)
    at Resource.build (http://localhost:8000/dist/amp.js:15589:20)
    at Resources.buildOrScheduleBuildForResource_ (http://localhost:8000/dist/amp.js:16461:18)
    at Resources.add (http://localhost:8000/dist/amp.js:16444:10)
    at amp-social-share.ElementProto.attachedCallback (http://localhost:8000/dist/amp.js:4384:21)
    at registerElement (http://localhost:8000/dist/amp.js:4983:16)
    at Object.upgradeOrRegisterElement (http://localhost:8000/dist/amp.js:3739:5)
    at Object.registerExtendedElement (http://localhost:8000/dist/amp.js:7101:18)

When the type attribute of amp-social-share is invalid, for example, contains space, the error thrown is the above. Maybe we could make the error more clear saying that the type attribute is not valid.

muxin avatar Aug 26 '16 06:08 muxin

/to @mkhatib

dvoytenko avatar Aug 26 '16 10:08 dvoytenko

This looks like a validation error and not thrown by runtime, can you confirm @muxin ?

mkhatib avatar Aug 26 '16 19:08 mkhatib

This is a runtime error, we could throw a better error message than this.

muxin avatar Aug 26 '16 20:08 muxin

definitely a runtime error. this is because we use the "type" value as a class name with spaces.

element.classList.add("whats app") // throws error

erwinmombay avatar Aug 26 '16 20:08 erwinmombay