Skip to content

Node Titles include trailing spaces #156

Description

@DontDieThankYou

What is the current behavior?

Node titles with trailing spaces include the space in the parsed node title. This contrasts with TryGetNodeTitle that trims the trailing space.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

define a node with a trailing space after the title:

title: Test 
---
===

Query for its existence:

public void TestLoadingNodes()
{
    var path = Path.Combine(TestDataPath, "Projects", "Basic", "Test.yarn");

    var result = Compiler.Compile(CompilationJob.CreateFromFiles(path));

    result.Diagnostics.Should().NotContain(d => d.Severity == Diagnostic.DiagnosticSeverity.Error); ;

    
    dialogue.Program = result.Program;
    dialogue.NodeExists("Test").Should().BeTrue(); //<- fails
    dialogue.NodeExists("Test ").Should().BeFalse(); //<- fails
}

This is more prevalent when adding comments to nodes ie:

title: Test // I introduced a space to the node title
---
===

What is the expected behavior?

The NodeTitle should be trimmed of spaces either when assigned during the Compile step or when lexing.

Please tell us about your environment

  • Operating System: Windows 11 10.0.262
  • Yarn Spinner Version: 3.2.7
  • Extension Version:
  • Unity Version: 6000.3.16f1

Other information

Potential fix:
Modifying YarnSpinner.Compiler\Compiler.cs 136

node.Node.NodeTitle = titleHeader.title?.Text; // from
node.Node.NodeTitle = titleHeader.title?.Text?.Trim(); // to

Alternatively, modifying the grammar to remove the WS? pre/postfix in HEADER_TITLE_ID (and put it in HEADER_TITLE_COMMENT or HEADER_TITLE_NEWLINE where the matched value is less consequential) or adding a custom lexer action to trim spaces may be cleaner.

Add tags

Core (compiler), Unity

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions