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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(cli): handle frontmatter ending with CRLF
On Windows, lines usually end with `\r\n`/CRLF/␍␊.

Although YAML supports this as a line-break, our regex was incorrectly
breaking this up, which was causing the `\r` character to be appending
into some strings, instead of `\r\n`.
  • Loading branch information
aloisklink committed Apr 22, 2024
commit 79451c15383a7628802afa66a3457829234a5780
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
@@ -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}`;
Loading