Skip to content

Errors if attempting to update a page whose title ends with spaces #672

@birjj

Description

@birjj

What happened?

If mark is given a title that ends with spaces (specifically we encountered this when both --title-from-h1 and --parents is set), then it will attempt to create the page even if it already exists. This causes Confluence to return an error with

$ go run main.go --files ../../Notes/confluence-markdown-test.md --space MySpace --title-from-h1 true --parents 'foo/bar'
...
2025-10-31 13:53:23.925 INFO  processing ../../Notes/confluence-markdown-test.md
2025-10-31 13:53:24.570 INFO  page will be stored under path: MySpace > foo > bar > There's a space here:
2025-10-31 13:53:24.691 FATAL can't create page "There's a space here: "
                              └─ the Confluence API returned unexpected status: 400 Bad Request, output: "{\"statusCode\":400,\"data\":{\"authorized\":true,\"valid\":true,\"errors\":[],\"successful\":true},\"message\":\"com.atlassian.confluence.api.service.exceptions.api.BadRequestException: A page with this title already exists: A page already exists with the same TITLE in this space\"}"

Note

This appears to be caused by Confluence trimming spaces when creating pages. This means that the following happens:

  • mark first calls Confluence to create a page called "There's a space here: ".
  • That causes Confluence to create a page titled "There's a space here:" (trimmed).
  • When mark is told to update the page it first asks Confluence if a page titled "There's a space here: " exists
  • No such page exists, so mark tells Confluence to create it. This causes Confluence to error since it trims the page title, sees that the trimmed page title already exists, and therefore fails.

What did you expect to happen?

Mark should succeed at updating the page, instead of trying to create it.

How can we reproduce the behavior you experienced?

Steps to reproduce the behavior:

  1. Create a markdown file with this content (note the space at the end of the first line):

    # There's a space here: 
    
    This is some content
  2. Run mark (replace go run main.go with mark if not developing):

    go run main.go --files ./path/to/file.md --space MySpace --title-from-h1 true --parents 'foo/bar'
  3. Run the exact same command again

Further Information (please complete the following information)

  • Mark Version (mark --version): mark version dev@none
  • Mark Parameters: --title-from-h1 --parents
  • Confluence Hosting: Cloud
  • Confluence Version: [e.g. v7.13]
  • Environment specific Information: [e.g. running in Github Actions, or on Mac OS X, etc.]

Logs or other output

2025-10-31 13:53:23.925 INFO  processing ../../Notes/confluence-markdown-test.md
2025-10-31 13:53:24.570 INFO  page will be stored under path: Developer Tooling :pineapple: > foo > bar > This is a test1
2025-10-31 13:53:24.691 FATAL can't create page "This is a test1 "
                              └─ the Confluence API returned unexpected status: 400 Bad Request, output: "{\"statusCode\":400,\"data\":{\"authorized\":true,\"valid\":true,\"errors\":[],\"successful\":true},\"message\":\"com.atlassian.confluence.api.service.exceptions.api.BadRequestException: A page with this title already exists: A page already exists with the same TITLE in this space\"}"

Additional context

We encountered this when running with both --parents and --title-from-h1. We're unsure if it also happens when running without them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions