Skip to content

Commit

Permalink
Merge pull request #338 from KevinBatdorf/escape-shortcodes
Browse files Browse the repository at this point in the history
Escape shortcodes
  • Loading branch information
KevinBatdorf authored Sep 29, 2024
2 parents 43b59d2 + ca0ffc7 commit 471fbe4
Show file tree
Hide file tree
Showing 34 changed files with 13,934 additions and 5,169 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

59 changes: 0 additions & 59 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-undef
module.exports = {
trailingComma: 'all',
tabWidth: 4,
Expand Down
2 changes: 1 addition & 1 deletion code-block-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://code-block-pro.com/?utm_campaign=plugin&utm_source=author-uri
* Requires at least: 6.0
* Requires PHP: 7.0
* Version: 1.26.4
* Version: 1.26.5
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: code-block-pro
Expand Down
18 changes: 9 additions & 9 deletions cypress/e2e/buttons.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ beforeEach(() => {
cy.loginUser();
cy.visitNewPageEditor();
cy.addBlock('kevinbatdorf/code-block-pro');
cy.getPostContent('.wp-block[class$="code-block-pro"]').should('exist');
cy.getPostContent('.wp-block[class*="code-block-pro"]').should('exist');

cy.focusBlock('code-block-pro', 'textarea');
cy.get('.wp-block[class$="code-block-pro"] textarea').should('have.focus');
cy.get('.wp-block[class*="code-block-pro"] textarea').should('have.focus');
});
afterEach(() => {
cy.saveDraft(); // so we can leave without an alert
Expand All @@ -18,14 +18,14 @@ context('Copy button', () => {
cy.openSideBarPanel('Buttons');

cy.get('[data-cy="copy-button"]').should('exist').should('be.checked');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'Copy');

cy.get('[data-cy="copy-button"]').uncheck();
cy.get('[data-cy="copy-button"]').should('not.be.checked');

cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('not.contain', 'Copy');
});
Expand All @@ -34,7 +34,7 @@ context('Copy button', () => {
cy.openSideBarPanel('Buttons');

cy.get('[data-cy="copy-button"]').should('exist').should('be.checked');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'M9 5H7a2 2 0 00-2 2v12a2') // Clipboard.tsx
.should('not.contain', 'M16.5 8.25V6a2.25 2.25'); // TwoSquares.tsx
Expand All @@ -46,7 +46,7 @@ context('Copy button', () => {
cy.get('#code-block-pro-copy-button-twoSquares').should('exist');
cy.get('#code-block-pro-copy-button-twoSquares').click();

cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'M16.5 8.25V6a2.25 2.25') // TwoSquares.tsx
.should('not.contain', 'M9 5H7a2 2 0 00-2 2v12a2'); // Clipboard.tsx
Expand Down Expand Up @@ -101,7 +101,7 @@ context('Copy button', () => {
cy.openSideBarPanel('Buttons');

cy.get('[data-cy="copy-button"]').should('exist').should('be.checked');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'M9 5H7a2 2 0 00-2 2v12a2') // Clipboard.tsx
.should('not.contain', '<span class="cbp-btn-text">Copy'); // TextSimple.tsx
Expand All @@ -114,7 +114,7 @@ context('Copy button', () => {
cy.get('#code-block-pro-copy-button-textSimple').click();

// Button changed - expected default text is shown
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', '<span class="cbp-btn-text">Copy') // TextSimple.tsx
.should('not.contain', 'M9 5H7a2 2 0 00-2 2v12a2'); // Clipboard.tsx
Expand All @@ -125,7 +125,7 @@ context('Copy button', () => {
.should('have.value', 'Copy')
.clear();
cy.get('#code-block-pro-copy-button-text').type('foo-bar-baz-lets-go');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', '<span class="cbp-btn-text">foo-bar-baz-lets-go')
.should('not.contain', '<span class="cbp-btn-text">Copy');
Expand Down
41 changes: 37 additions & 4 deletions cypress/e2e/extra-settings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ beforeEach(() => {
cy.loginUser();
cy.visitNewPageEditor();
cy.addBlock('kevinbatdorf/code-block-pro');
cy.getPostContent('.wp-block[class$="code-block-pro"]').should('exist');
cy.getPostContent('.wp-block[class*="code-block-pro"]').should('exist');

cy.focusBlock('code-block-pro', 'textarea');
cy.get('.wp-block[class$="code-block-pro"] textarea').should('have.focus');
cy.get('.wp-block[class*="code-block-pro"] textarea').should('have.focus');
});
afterEach(() => {
cy.saveDraft(); // so we can leave without an alert
Expand All @@ -25,7 +25,7 @@ context('Extra Settings', () => {
codeOutput: '<script><</script>',
});

cy.getPostContent('.wp-block[class$="code-block-pro"] pre')
cy.getPostContent('.wp-block[class*="code-block-pro"] pre')
.invoke('html')
.should('not.contain', encodeURI('<'));

Expand All @@ -43,7 +43,7 @@ context('Extra Settings', () => {

cy.addCode('<script>&lt;</script>');

cy.getPostContent('.wp-block[class$="code-block-pro"] pre')
cy.getPostContent('.wp-block[class*="code-block-pro"] pre')
.invoke('html')
.should('contain', '>lt</span>'); // formatted with highlighter

Expand All @@ -53,4 +53,37 @@ context('Extra Settings', () => {
.should('exist')
.should('contain', '<script>&lt;</script>');
});

it('Escapes WordPress shortcodes', () => {
cy.openSideBarPanel('Extra Settings');
cy.get('[data-cy="use-escape-shortcodes"]')
.should('exist')
.should('not.be.checked');

cy.setLanguage('plaintext');
cy.addCode('[embed]foo[/embed]');
cy.getPostContent('.wp-block[class*="code-block-pro"] pre')
.invoke('html')
.should('contain', '[embed]foo[/embed]'); // Doesn't render

cy.previewCurrentPage();
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
.should('exist')
.invoke('html')
.should('contain', '<a href="http://foo">foo</a>'); // Renders

cy.go('back');
cy.focusBlock('code-block-pro');
cy.openSideBarPanel('Extra Settings');
cy.get('[data-cy="use-escape-shortcodes"]').check();
cy.getPostContent('.wp-block[class*="code-block-pro"] pre')
.invoke('html')
.should('contain', '[embed]foo[/embed]'); // Doesn't render

cy.previewCurrentPage();
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
.should('exist')
.invoke('html')
.should('contain', '[embed]foo[/embed]'); // Doesn't render
});
});
18 changes: 9 additions & 9 deletions cypress/e2e/footers.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ beforeEach(() => {
cy.loginUser();
cy.visitNewPageEditor();
cy.addBlock('kevinbatdorf/code-block-pro');
cy.getPostContent('.wp-block[class$="code-block-pro"]').should('exist');
cy.getPostContent('.wp-block[class*="code-block-pro"]').should('exist');

cy.focusBlock('code-block-pro', 'textarea');
cy.get('.wp-block[class$="code-block-pro"] textarea').should('have.focus');
cy.get('.wp-block[class*="code-block-pro"] textarea').should('have.focus');
});
afterEach(() => {
cy.saveDraft(); // so we can leave without an alert
cy.logoutUser();
});
context('Footers', () => {
it('Renders no footer on insert and can swap', () => {
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.find('div')
.first()
.siblings()
.should('have.length', 2);
cy.setFooter('simpleStringEnd');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.find('div')
.first()
.siblings()
.should('have.length', 3);
cy.setFooter('none');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.find('div')
.first()
.siblings()
Expand All @@ -37,23 +37,23 @@ context('Footers', () => {
// Remove the header/footer if there
cy.setHeader('none');
cy.setFooter('none');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('not.contain', 'JavaScript');
cy.setFooter('simpleStringEnd');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'JavaScript');
cy.setLanguage('ruby');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'Ruby');
cy.openSideBarPanel('Settings');
cy.get('#code-block-pro-footer-text')
.should('exist')
.should('have.value', '')
.type('foo-bar-baz-lets-go');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'foo-bar-baz-lets-go')
.should('not.contain', 'Ruby')
Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/headers.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@ beforeEach(() => {
cy.loginUser();
cy.visitNewPageEditor();
cy.addBlock('kevinbatdorf/code-block-pro');
cy.getPostContent('.wp-block[class$="code-block-pro"]').should('exist');
cy.getPostContent('.wp-block[class*="code-block-pro"]').should('exist');

cy.focusBlock('code-block-pro', 'textarea');
cy.get('.wp-block[class$="code-block-pro"] textarea').should('have.focus');
cy.get('.wp-block[class*="code-block-pro"] textarea').should('have.focus');
});
afterEach(() => {
cy.saveDraft(); // so we can leave without an alert
cy.logoutUser();
});
context('Headers', () => {
it('Renders default header and can switch', () => {
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'fill="#FF5F56" stroke="#E0443E"');
cy.setHeader('headlightsMuted');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('not.contain', 'fill="#FF5F56" stroke="#E0443E"')
.should('contain', 'fill="#d8dee933" stroke="#d8dee94d"');
});
it('Can accept text inputs on some headers', () => {
cy.setHeader('simpleString');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'JavaScript');
cy.setLanguage('ruby');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'Ruby');
cy.openSideBarPanel('Settings');
cy.get('#code-block-pro-header-text')
.should('exist')
.should('have.value', '')
.type('Hello WordPress');
cy.getPostContent('.wp-block[class$="code-block-pro"]')
cy.getPostContent('.wp-block[class*="code-block-pro"]')
.invoke('html')
.should('contain', 'Hello WordPress')
.should('not.contain', 'Ruby')
Expand Down
Loading

0 comments on commit 471fbe4

Please sign in to comment.