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

Editor: Ensure Copy button in sidebar copies whole permalink, *with* URL protocol #61876

Merged
merged 4 commits into from
May 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/editor/src/components/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { useCopyToClipboard } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { usePostURLLabel } from './label';
import { store as editorStore } from '../../store';

/**
Expand Down Expand Up @@ -62,8 +61,11 @@ export default function PostURL( { onClose } ) {
const { editPost } = useDispatch( editorStore );
const { createNotice } = useDispatch( noticesStore );
const [ forceEmptyField, setForceEmptyField ] = useState( false );
const postUrlLabel = usePostURLLabel();
const copyButtonRef = useCopyToClipboard( postUrlLabel, () => {
const permalink = useSelect(
( select ) => select( editorStore ).getPermalink(),
[]
);
const copyButtonRef = useCopyToClipboard( permalink, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also use safeDecodeURIComponent for the copied permalink.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ntsekouras: Is it needed in practice? I had a quick look at getPermalink, getPermalinkParts and I don't see where we'd get encoded components from. Also:

Screenshot 2024-05-23 at 10 24 02

In the above scenario I see http://localhost:8881/2024/05/ola-φίλε/ in my clipboard, as expected.

Finally, I also just refactored to use the existing useSelect call in that component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm.. yesterday I tested with some greek and accents and it produced a URL that needed it. Don't remember what I tried exactly though and couldn't reproduce today with random tests, that could be similar to the yesterday ones..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I should just add the decoder to be safe?

createNotice( 'info', __( 'Copied URL to clipboard.' ), {
isDismissible: true,
type: 'snackbar',
Expand Down
Loading