dotCMS / dotCMS/core

Block Editor: link marks with no target render target="null" in Story Block VTL, causing every "same-window" link to open a new tab

Open Beginner friendly
#37,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OKR : Customer Support Team : Maintenance
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem Statement

Problem Statement

When a link has no explicit target (the normal case for any link meant to open in the
same window), $mark.attrs.target is null. $esc.html(null) renders the literal string
"null" rather than an empty string, so the output is:

<a href="/some/page" target="null" ...>Some Link

Per the HTML living standard, a target value that isn't one of the reserved keywords
(_blank, _self, _parent, _top) is treated as the name of a browsing context. Since no
browsing context named "null" exists yet, the browser creates a new one — i.e. it opens a
new tab/window — exactly as if target="_blank" had been set. Every same-window link
authored via the Block Editor is affected, on every dotCMS site, whenever the link's target
was never explicitly set.

renderMarks is used by #macro(renderContentBlock) for every text-bearing node (paragraph,
heading, list item, table cell, blockquote), so this hits any Block Editor field rendered via
the traditional (VTL) delivery path.

#macro(renderMarks) in VM_global_library.vm renders the target attribute on every
link mark unconditionally, with no null guard — unlike title, aria-label, and rel
right below it, which are all correctly gated behind #if(...):

https://github.com/dotCMS/core/blob/main/dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm#L36-L40

*#<a href="${esc.html($mark.attrs.href)}" target="${esc.html($mark.attrs.target)}"#*
*##if($mark.attrs.title) title="${esc.html($mark.attrs.title)}"#end#*
*##if($mark.attrs.get("aria-label")) aria-label="${esc.html($mark.attrs.get("aria-label"))}"#end#*
*##if($mark.attrs.rel) rel="${esc.html($mark.attrs.rel)}"#end#*
*#>#*

### Steps to Reproduce

1. In any Block Editor field, add a text link and leave "Target" unset (the default — do not
2. choose "New window").
3. Publish the page.
4. View the published page and inspect the rendered <a> for that link — note
5. target="null".
6. Click the link — it opens in a new tab, even though no one selected "open in new window."


https://drive.google.com/file/d/1_DPxjfkldqpVj-CZeIffYatpX85DyZL_/view?usp=drive_link

### Acceptance Criteria

Expected: a link with no explicit target renders with no target attribute at all
(or an equivalent same-window value), and opens in the same tab.

Actual: the link renders target="null" and opens in a new tab/window.

### dotCMS Version

26.09.14-01
26.09.17-02

### Severity

Low - Minor issue or cosmetic

### Links

https://dotcms.freshdesk.com/a/tickets/39485

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm at #macro(renderMarks), where the link mark target is rendered. Reproduce a Block Editor link with no target through the VTL delivery path and verify that the finished output omits target when it is null and opens in the same tab.

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.