Skip to content

text/unstable-dedent strips too many trailing newlines #6831

@lionel-rowe

Description

@lionel-rowe

Describe the bug

text/unstable-dedent should only strip a single trailing newline, but instead it strips all trailing newlines.

Steps to Reproduce

import { assertEquals } from 'jsr:@std/assert';
import { dedent as stdDedent } from 'jsr:@std/text@1.0.16/unstable-dedent';
import npmDedent from 'npm:string-dedent@3.0.2';

for (const [name, dedent] of Object.entries({
  'jsr:@std': stdDedent,
  'npm:string-dedent': npmDedent,
})) {
  Deno.test(name, async (t) => {
    const v1 = dedent`
      a

    `;

    // throws for jsr:@std, ok for npm:string-dedent
    await t.step('v1', () => assertEquals(v1, 'a\n'));

    const v2 = dedent`
      a\n
    `;

    // throws for jsr:@std, ok for npm:string-dedent
    await t.step('v2', () => assertEquals(v2, 'a\n'));
  });
}

Expected behavior

Only strip a single trailing newline.

Environment

text@1.0.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions