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

fix(cli): improve handling of Windows CRLF line endings #25

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
matrix:
node: ['18.18.x']
pkg: ['sdk', 'cli']
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on:
labels: ubuntu-latest
labels: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Improve handling of Windows CRLF line-endings

## [0.1.0] - 2024-04-22

Initial release.
6 changes: 4 additions & 2 deletions packages/cli/src/commander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,10 @@ describe('link', () => {
expect(file).toMatch(idLineRegex);
// other than the added `id: xxxx` field, everything else should be identical,
// although in practice, we'd expect some formatting changes
expect(file.replace(idLineRegex, '')).toStrictEqual(
await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' }),
//
// We also normalize line endings to LF to avoid issues with CRLF on Windows
expect(file.replace(idLineRegex, '').replaceAll('\r\n', '\n')).toStrictEqual(
(await readFile(UNUSUAL_MARKDOWN_FILE, { encoding: 'utf8' })).replaceAll('\r\n', '\n'),
);
});
});
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/frontmatter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from 'vitest';
import { extractFrontMatter } from './frontmatter.js';

describe('extractFrontMatter()', () => {
it(String.raw`should handle \r\n (␍␊)`, () => {
const text = '---\r\nid: test\r\n---\r\ninfo\r\n';
const result = extractFrontMatter(text);
expect(result.metadata.id).toBe('test');
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { parseDocument, type Document, YAMLMap, isMap } from 'yaml';

const frontMatterRegex = /^-{3}\s*[\n\r](.*?)[\n\r]-{3}\s*[\n\r]+/s;
const frontMatterRegex = /^-{3}\s*[\n\r](.*?[\n\r])-{3}\s*[\n\r]+/s;
const urlIDRegex = /(?<baseURL>.*)\/d\/(?<documentID>[\w-]+)/;

type UrlID = `${string}/d/${string}`;
Expand Down
Loading