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

Prevent using document.domain by Firefox in the preview plugin #5439

Merged
merged 5 commits into from
Apr 11, 2023

Conversation

KarolDawidziuk
Copy link
Contributor

What is the purpose of this pull request?

Task

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#5412](https://github.com/ckeditor/ckeditor4/issues/5412): Prevent using `document.domain` by Firefox in the `preview` plugin.

What changes did you make?

In the previous PR with fixing print on Firefox, we allowed using document.domain to properly open the preview before print while using the editor from CDN. Looks like FF fixed this and we can remove it.
Additionally, we could simplify the code more by removing fix for creating links to anchor.

Which issues does your PR resolve?

Closes #5412.

@Comandeer Comandeer self-requested a review March 10, 2023 16:22
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

The changes seem to work properly, there are some more opportunities to simplify the code and we should probably update our tests a bit. Please, see my inline comments for more info.

nativePreviewWindow,
previewUrl = '',
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this variable at all? We could skip it altogether and just inline an empty string in the window.open() call.

Comment on lines 137 to 142
function generateBaseTag() {
var template = '<base href="{HREF}">',
origin = location.origin,
pathname = location.pathname;

if ( !config.baseHref && !CKEDITOR.env.gecko ) {
return '';
}
var template = '<base href="{HREF}">';

if ( config.baseHref ) {
return template.replace( '{HREF}', config.baseHref );
}

// As we use HTML file in Gecko, we must fix the incorrect base for
// relative paths.
pathname = pathname.split( '/' );
pathname.pop();
pathname = pathname.join( '/' );

return template.replace( '{HREF}', origin + pathname + '/' );
return '';
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we can't simplify it even further, e.g. do we need the template at all?

Suggested change
function generateBaseTag() {
var template = '<base href="{HREF}">',
origin = location.origin,
pathname = location.pathname;
if ( !config.baseHref && !CKEDITOR.env.gecko ) {
return '';
}
var template = '<base href="{HREF}">';
if ( config.baseHref ) {
return template.replace( '{HREF}', config.baseHref );
}
// As we use HTML file in Gecko, we must fix the incorrect base for
// relative paths.
pathname = pathname.split( '/' );
pathname.pop();
pathname = pathname.join( '/' );
return template.replace( '{HREF}', origin + pathname + '/' );
return '';
}
function generateBaseTag() {
if ( !config.baseHref ) {
return '';
}
return '<base href="' + config.baseHref + '">';
}

}

// With Firefox only, we need to open a special preview page, so
// anchors will work properly on it (https://dev.ckeditor.com/ticket/9047).
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a manual test that will allow verifying if this issue is really not-reproducible anymore?

@@ -212,8 +200,7 @@
}

function getPreviewLocation() {
// #(4444)
Copy link
Member

Choose a reason for hiding this comment

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

Also, it would be good to update manual tests for #444 to test if it still works (simply by adding the new version and issue tags).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume you were referring to #4444?

Copy link
Member

Choose a reason for hiding this comment

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

Yes 🙈

@KarolDawidziuk
Copy link
Contributor Author

Thanks, @Comandeer for your input. I've applied changes mentioned in your comments and PR is ready for another review.

@github-actions
Copy link

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Apr 11, 2023
@KarolDawidziuk KarolDawidziuk removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Apr 11, 2023
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

LGTM!

@Comandeer Comandeer merged commit 9735075 into master Apr 11, 2023
@Comandeer Comandeer deleted the t/5412 branch April 11, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature plan about document.domain in ckeditor
2 participants