Improve the mise.toml parser to conform to the TOML specification

Fixed #867 ("mise.toml parser fails when ruby line contains
end-of-line comments")

Co-authored-by: Riley Ho <riley@rileychh.dev>
This commit is contained in:
Yi-Jyun Pan
2026-01-30 15:50:30 +01:00
committed by Benoit Daloze
co-authored by Riley Ho
parent 90be1154f9
commit 8d27f39a5e
2 changed files with 2 additions and 2 deletions
Generated Vendored
+1 -1
View File
@@ -92559,7 +92559,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
console.log(`Using ${rubyVersion} as input from file .tool-versions`) console.log(`Using ${rubyVersion} as input from file .tool-versions`)
} else if (rubyVersion === 'mise.toml') { // Read from mise.toml } else if (rubyVersion === 'mise.toml') { // Read from mise.toml
const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim()
const regexp = /^ruby\s*=\s*['"](.+)['"]$/ const regexp = /^\s*ruby\s*=\s*['"]([^'"]+)['"]\s*(?:#.*)?$/
const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0]
rubyVersion = rubyLine.match(regexp)[1] rubyVersion = rubyLine.match(regexp)[1]
console.log(`Using ${rubyVersion} as input from file mise.toml`) console.log(`Using ${rubyVersion} as input from file mise.toml`)
+1 -1
View File
@@ -130,7 +130,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
console.log(`Using ${rubyVersion} as input from file .tool-versions`) console.log(`Using ${rubyVersion} as input from file .tool-versions`)
} else if (rubyVersion === 'mise.toml') { // Read from mise.toml } else if (rubyVersion === 'mise.toml') { // Read from mise.toml
const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim()
const regexp = /^ruby\s*=\s*['"](.+)['"]$/ const regexp = /^\s*ruby\s*=\s*['"]([^'"]+)['"]\s*(?:#.*)?$/
const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0]
rubyVersion = rubyLine.match(regexp)[1] rubyVersion = rubyLine.match(regexp)[1]
console.log(`Using ${rubyVersion} as input from file mise.toml`) console.log(`Using ${rubyVersion} as input from file mise.toml`)