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

Line-breaks in topic titles causing builds to fail #47

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

super-structure
Copy link
Contributor

Trailing line breaks within topic <title> elements of cause builds to fail when the search result previews are generated (at taskname gen-preview-json). This appears to be when converting the title contents from text node to attribute value in merge-data.xsl.

Simply wrapping the existing xpath in a normalize-space() function resolves the issue; at least for leading or trailing line breaks.

wrap previous xpath in a normalize-space() function to prevent trailing or leading line breaks from causing issues with generating search previews
…-breaks

Update title attr in extract-data.xsl
@jason-fox jason-fox added the bug Something isn't working label Mar 9, 2024
@infotexture
Copy link
Owner

@super-structure Thanks for reporting this and proposing the fix.

I can't seem to reproduce the issue. I tested with a long topic title that contained multiple line breaks and everything still worked fine:

DITA-Bootstrap-Lunr-PR47-linebreaks@2x

Can you provide more details on the circumstances that cause the problem?

@super-structure
Copy link
Contributor Author

super-structure commented Mar 12, 2024

@infotexture Sure! And I should have specified line feeds instead of line breaks. I narrowed down the issue to the following topic title element:

   <title> Security Release Notes
	 </title>

I just noticed that there is a line feed, tab, and trailing space in that title. I had suspected it was the line feed, though it could be any combination of those I suppose.

Copy link
Collaborator

@jason-fox jason-fox left a comment

Choose a reason for hiding this comment

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

LGTM.

@jason-fox
Copy link
Collaborator

I couldn't reproduce the error at first, but that is because I was editing the DITA Bootstrap sample like @infotexture which includes an .editorconfig like this:

indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

Now when I deliberately remove that and deliberate change the title I can reproduce the error, and normalize-space() seems to fix it since by definition normalize-space() :

  • Removes all leading spaces.
  • Removes all trailing spaces.
  • Replaces any group of consecutive whitespace characters with a single space.

Which will remove any \t or \r\n nonsense from the Title in the JSON.

@jason-fox jason-fox merged commit 657c76c into infotexture:develop Mar 13, 2024
1 check passed
@infotexture
Copy link
Owner

@jason-fox Thanks for reviewing and merging.

It's easy to forget that .editorconfig prevents stuff like this from creeping in, and a good reminder that linting tools are incredibly useful. But not everyone uses them, so certainly make sense to ship this fix. 👍

jason-fox added a commit that referenced this pull request May 27, 2024
This seems related to issue #47 , but it's showing up in a different
place. Here, it seems that the line breaks are not being escaped in the
resulting lunr.json file for the search functionality.

## Suggested resolution
As the whitespace in a title (whether intentional or not) isn't really
relevant to the search functionality, simply using the same replace
function in xpath as is used elsewhere in the `data-to-json.xsl` file
seems a simple and consistent fix for this issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants