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

Htaccess Syntax Errors #110

Closed
ghost opened this issue Jun 10, 2020 · 11 comments · Fixed by #118 or #119
Closed

Htaccess Syntax Errors #110

ghost opened this issue Jun 10, 2020 · 11 comments · Fixed by #118 or #119
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jun 10, 2020

Hi,

I was going to create a content regarding Jeff Star's (Perishablepress) 7G Firewall Rules for htaccess. However, something breaks the code.

The first issue appears after highlighting the code:
Screen-Shot-2020-06-06-at-21.19.34b569f2d18c9a5d16.png

The second issue: I copied the original code without editing from txt file to Gutenberg block via Syntax highlighting code block.

But the code has been changed. To clarify check the difference please.
Original line:
RewriteCond %{REQUEST_URI} (/)(\*|\"|\'|\.|,|&|&?)/?$ [NC,OR]

it is changed by Syntax highlighting code block like that:
RewriteCond %{REQUEST_URI} (/)(\*|\"|\'|\.|,|&|&?)/?$ [NC,OR]

Also another original line:
RewriteCond %{HTTP_USER_AGENT} (<|%0a|%0d|%27|%3c|%3e|%00|0x00) [NC,OR]

Changed by Syntax highlighting code block:
RewriteCond %{HTTP_USER_AGENT} (<|%0a|%0d|%27|%3c|%3e|%00|0x00) [NC,OR]

But if I encode all the code, then no issue at all and The Syntax highlighting code block plugin shows the exact code without changing it. So should I encode codes before inserting them to Gutenberg? Do you recommend doing that?

NOTE: Highlighting issue is still there whether encode them or not.

Regards.

@westonruter
Copy link
Owner

The encoding issue may be a bug in Gutenberg. Do you experience that issue even without this plugin active?

In regards to the highlighting issue, @allejo do you think this is an issue with the language definition?

@ghost
Copy link
Author

ghost commented Jun 10, 2020

Yes. Although I don't encode code, Gutenberg doesn't edit/change any line.

Without the plugin:
7g-firewall-syntaxaa11047b50349587.png

@westonruter
Copy link
Owner

What is the URL for the page that has that .htaccess code to copy/paste from?

@ghost
Copy link
Author

ghost commented Jun 12, 2020

It is a website which is currently under development. So I installed the same plugin on another website and created a sample page for you.

Check this please:
https://serdarwork.com/sample-page/

To download the original txt file:
https://perishablepress.com/downloads/16621/

Thank you!
Kind regards.

@westonruter
Copy link
Owner

No, I mean where can we find the code you're using to copy/paste?

@ghost
Copy link
Author

ghost commented Jun 12, 2020

Sorry about that. Here is the link:
https://perishablepress.com/7g-firewall/

To directly download:
https://perishablepress.com/downloads/16621/

@allejo
Copy link
Collaborator

allejo commented Jun 14, 2020

In regards to the highlighting issue, @allejo do you think this is an issue with the language definition?

I haven't tested this code specifically yet, but yea I would imagine the regex in the language definition is breaking.

@westonruter westonruter added the bug Something isn't working label Jun 21, 2020
@westonruter
Copy link
Owner

If I try adding the block with this plugin deactivated, and then I activate the plugin and reload the editor, it shows a parse error:

image

Somehow, our HighlightablePlainText component is failing to handle this markup. In our version we render the text via:

<PlainText ref={plainTextRef} {...props} />

In WordPress 5.4, the code used is:

		<div className={ className }>
			<PlainText
				value={ attributes.content }
				onChange={ ( content ) => setAttributes( { content } ) }
				placeholder={ __( 'Write code…' ) }
				aria-label={ __( 'Code' ) }
			/>
		</div>

Not sure why this would make a difference.

In the console, when this plugin is active there is a block validation error:

image

Content generated by save function:

image

Content retrieved from post body:

image

So this leads me to think the issue is that our save function is not doing HTML encoding as it needs to be!

Our function is:

save({ attributes }) {
return (
<pre>
<code>{attributes.content}</code>
</pre>
);
},

But, look at this… the code in Gutenberg is different:

import { escape } from './utils';

export default function save( { attributes } ) {
	return (
		<pre>
			<code>{ escape( attributes.content ) }</code>
		</pre>
	);
}

So it seems the only thing we're missing is escape()!

@westonruter
Copy link
Owner

@WPLibrary Here's a PR with the fix and a build for testing: #118

@westonruter
Copy link
Owner

In my testing, the fix is not reliable as sometimes the save function ends up undefined. See #118 (comment).

@westonruter
Copy link
Owner

@WPLibrary Would you test this update please: #119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants