Skip to content

Commit

Permalink
Normalize CRLF to LF when parsing TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Oct 21, 2024
1 parent e21013a commit f549c34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11549,13 +11549,17 @@ function getWorkingDirectory() {
}
return workdir;
}
function parseTOMLNormalized(input) {
const normalized = input.replace(/\r\n$/g, '\n');
return (0, toml_1.parse)(normalized);
}
function getManifestDir(args) {
const workdir = getWorkingDirectory();
const manifestPath = getCliValue(args, '--manifest-path') || getCliValue(args, '-m');
return manifestPath ? path.dirname(path.join(workdir, manifestPath)) : workdir;
}
function parseRustToolchain(content) {
const toml = (0, toml_1.parse)(content.toString());
const toml = parseTOMLNormalized(content.toString());
const toolchain = toml === null || toml === void 0 ? void 0 : toml.toolchain;
return (toolchain === null || toolchain === void 0 ? void 0 : toolchain.channel) || '';
}
Expand Down Expand Up @@ -11650,7 +11654,7 @@ async function findVersion(args) {
const pyprojectToml = path.join(manifestDir, 'pyproject.toml');
if ((0, fs_1.existsSync)(pyprojectToml)) {
const content = await fs_1.promises.readFile(pyprojectToml);
const toml = (0, toml_1.parse)(content.toString());
const toml = parseTOMLNormalized(content.toString());
const buildSystem = (toml['build-system'] || {});
const requires = (buildSystem['requires'] || []);
const maturin = requires.find(req => req.startsWith('maturin'));
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ function getWorkingDirectory(): string {
return workdir
}

function parseTOMLNormalized(input: string): JsonMap {
// Normalize CRLF to LF to avoid hitting https://github.com/iarna/iarna-toml/issues/33
const normalized = input.replace(/\r\n$/g, '\n')
return parseTOML(normalized)
}

function getManifestDir(args: string[]): string {
const workdir = getWorkingDirectory()
const manifestPath =
Expand All @@ -229,7 +235,7 @@ function getManifestDir(args: string[]): string {
}

function parseRustToolchain(content: string): string {
const toml = parseTOML(content.toString())
const toml = parseTOMLNormalized(content.toString())
const toolchain = toml?.toolchain as JsonMap
return (toolchain?.channel as string) || ''
}
Expand Down Expand Up @@ -356,7 +362,7 @@ async function findVersion(args: string[]): Promise<string> {
const pyprojectToml = path.join(manifestDir, 'pyproject.toml')
if (existsSync(pyprojectToml)) {
const content = await fs.readFile(pyprojectToml)
const toml = parseTOML(content.toString())
const toml = parseTOMLNormalized(content.toString())
const buildSystem = (toml['build-system'] || {}) as JsonMap
const requires = (buildSystem['requires'] || []) as string[]
const maturin = requires.find(req => req.startsWith('maturin'))
Expand Down

0 comments on commit f549c34

Please sign in to comment.