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

Quotes on shortcode parameters are being escaped #4692

Closed
dartiss opened this issue Jan 26, 2018 · 10 comments
Closed

Quotes on shortcode parameters are being escaped #4692

dartiss opened this issue Jan 26, 2018 · 10 comments
Labels
[Type] Bug An existing feature does not function as intended

Comments

@dartiss
Copy link

dartiss commented Jan 26, 2018

I'm using WordPress 4.9.2 and Gutenberg 2.1.0.

I'm finding when I'm trying to add shortcode parameters that need quotes (double, single, or whatever) around them, that they're being escaped.

So, I use a plugin that allows me, via a shortcode, to add updates to a post. If I add the following into a block...

[update title="The latest update"]Some text here[/update]

This is showing correctly visually but when switching to HTML is shows as...

[update title="The latest update"]Some text here[/update]

Obviously, when viewed on the site, it displays incorrectly because of the escaping.

Now, this doesn't happen if the shortcode is added as a shortcode block - only if it's added inline or written out manually into a paragraph, for example.

@jeffpaul jeffpaul added the [Type] Bug An existing feature does not function as intended label Feb 1, 2018
@alanef
Copy link

alanef commented Feb 27, 2018

WP 4.9.4 and 2.2.0

Gutenberg passes escaped quotes to the shortcode atts - the consequence is if the atts are used in JS the JS breaks

Switch to classic = no issue

@bobbingwide
Copy link
Contributor

bobbingwide commented Mar 5, 2018

I'm trying to write a block that will generate a shortcode so that I can re-use an existing solution in a hybrid environment where the content was originally created in the classic-editor using shortcodes.

The HTML for the shortcode is generated correctly by the edit method ... it's displayed correctly in edit.
But on saving, double quotes get converted to " and single quotes get converted to '

I believe that I might be able to use <RawHTML> to achieve this, as this is what's used in the shortcode block, but can't figure out how to do it in my own code.

@mattyrob
Copy link

@bobbingwide

I might be able to help with this - I have a block for a shortcode that I'm trying to give a UI to for the parameters. The deprecation of allowing HTML to be passed and forcing RawHTML or createElement is causing me problems. Ping me if you want my code.

@bobbingwide
Copy link
Contributor

@mattyrob Perhaps you'd like to compare your code with mine.
In my Countdown block I did manage to implement a solution using <RawHTML>
See https://github.com/bobbingwide/oik-block/blob/master/blocks/oik-countdown/index.js

@mattyrob
Copy link

@bobbingwide

Thanks for that link - my code is in ES5 so I'm trying to call RawHTML as a function and it's not really working at the moment. I don't think <RawHTML> will work in my code.

@rhyswynne
Copy link

I'm having the same issue as @mattyrob. My blocks right now are outputting a Title, introduction paragraph then a shortcode. My save function is this:-

return ( el( 'div', { className: props.className }, el( 'h2', { className: 'wpec-title'}, attributes.title ), el( 'p', { className: 'wpec-description' }, attributes.subscriptiondetails ), wp.element.RawHTML( { props , emailcaptureform } ) ) ); }, } );

The problem arises is when output instead of the form, we're getting the following:-

<div props="[object Object]" emailcaptureform="[email_capture_form buttontext=&quot;Test%20Button&quot;]"></div>

I don't think I need props (In fact I'm fairly confident I don't), but it would be good to get an example of how wp.element.RawHTML will work, as most code is ES6.

@mattyrob
Copy link

@rhyswynne

I ended up using the following:
return el( element.RawHTML, null, '<p>my unescaped text here</p>' );

I hope that helps you.

@rhyswynne
Copy link

Thank you! It did :)

@bobbingwide
Copy link
Contributor

At WordCamp London contributor day @dartiss confirmed that #5897 resolves the issues with quotes in shortcodes being serialized. It resolve the issue for both double and single quotes.
The PR does not resolve issue #4456

@mcsf
Copy link
Contributor

mcsf commented Apr 17, 2018

Closed via #5897

@mcsf mcsf closed this as completed Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants