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

Linking to Craft Entry appends persistent hashtag #entry:77@1:url #197

Closed
akukral opened this issue Mar 21, 2024 · 4 comments
Closed

Linking to Craft Entry appends persistent hashtag #entry:77@1:url #197

akukral opened this issue Mar 21, 2024 · 4 comments
Assignees
Labels

Comments

@akukral
Copy link

akukral commented Mar 21, 2024

Description

When adding links within the CKEditor field via the link dropdown to an internal existing entry page the hashtag appended to the URL persists when rendering in a front-end template.

Previously as an example in CKEditor v 3.8.1 this #entry: hashtag was stripped when rendering in a template.

Steps to reproduce

  1. Highlight text in rich text field.
  2. Click dropdown for link
  3. Click link to entry
    image
  4. Select entry and confirm
  5. Check link URL in CKEditor, confirm existence of #entry: hashtag
    image
  6. Save entry
  7. Check template rendered with {{ entry.excerpt }}
  8. Link/URL to the entry is correct though the #entry:77@1:url appended in the rich text field persists.

Additional info

  • Local setup ddev version v1.22.7

  • Craft version: 5.0.0-beta.10

  • PHP version: 8.2.15

  • Database driver & version: MySQL 8.0.33

  • Plugins & versions:
    CK Editor: 4.0.x-dev
    Embedded Assets 5.0.0-beta.1
    Freeform 5.1.4
    Minify v5.x-dev
    SEOmatic v5.x-dev

  • CK Editor Config
    return { style: { definitions: [ { classes: [ 'brand-blue', ], element: 'span', name: 'Brand Blue', }, ], }, }

@akukral akukral added the bug label Mar 21, 2024
@akukral akukral changed the title Linking to Craft Entry appends persistent hashtag #entry:2@1:url Linking to Craft Entry appends persistent hashtag #entry:77@1:url Mar 21, 2024
@mfell
Copy link

mfell commented Apr 5, 2024

I can confirm this: Craft 5.0.1 // CKEditor 4.0.3

@akukral
Copy link
Author

akukral commented Apr 5, 2024

Until this is addressed I'm using this javascript code to strip this out on the front end to some effect.

function rewriteLinks(stringToStrip) {
  // Regular expression to match the string to strip with optional delimiters
  const regex = new RegExp(`(?:/|\\?|&)?${stringToStrip}(?:/|\\?|&)?`, 'g');

  const links = document.querySelectorAll('a');

  for (const link of links) {
    const href = link.href;
    const newHref = href.replace(regex, '');

    // Check if the URL changed to avoid unnecessary modifications
    if (href !== newHref) {
      link.href = newHref;
    }
  }
}

rewriteLinks('#entry:(.*?):url');

@i-just i-just self-assigned this Apr 5, 2024
@i-just
Copy link
Contributor

i-just commented Apr 5, 2024

Hi, thanks for reporting! I raised a PR for this.

@brandonkelly
Copy link
Member

CKEditor 4.0.4 is out with a fix for this. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants