mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
fix(sync): decode the whole block when the name line is not a string
A multi-line quoted name such as "proto\ followed by an indented line fails to decode alone, and the literal first line was returned, so the skill was skipped. Decode the whole frontmatter whenever the name line does not decode to a string; keep the literal only for frontmatter YAML rejects.
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
// allows (flow mapping, block scalar, alias, merge key, explicit key, ...) leaves the
|
||||
// scan without a name, and then the whole block is decoded.
|
||||
func ParseSkillName(skillPath string) (string, error) {
|
||||
name, indent := "", -1
|
||||
name, literal, indent := "", "", -1
|
||||
path := filepath.Join(skillPath, "SKILL.md")
|
||||
err := scanLenientBlock(path, func(raw []byte) bool {
|
||||
line := string(raw)
|
||||
@@ -35,7 +35,9 @@ func ParseSkillName(skillPath string) (string, error) {
|
||||
if v := strings.TrimSpace(value); v != "" && strings.ContainsRune("*|>&!", rune(v[0])) {
|
||||
return false // alias, block scalar, anchor or tag: decode the whole block
|
||||
}
|
||||
// The line alone decodes quotes and a trailing comment; a value YAML rejects is read as is.
|
||||
// The line alone decodes quotes and a trailing comment. When it does not decode to
|
||||
// a string (a multi-line quoted scalar, a number), the whole block is decoded, and
|
||||
// the line read as is is kept for frontmatter YAML rejects.
|
||||
var fm map[string]any
|
||||
if yaml.Unmarshal([]byte("name:"+value), &fm) == nil {
|
||||
if v, isString := fm["name"].(string); isString {
|
||||
@@ -43,7 +45,7 @@ func ParseSkillName(skillPath string) (string, error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
name = strings.Trim(strings.TrimSpace(value), `"'`)
|
||||
literal = strings.Trim(strings.TrimSpace(value), `"'`)
|
||||
return false
|
||||
})
|
||||
if err != nil || name != "" {
|
||||
@@ -53,8 +55,10 @@ func ParseSkillName(skillPath string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
name, _ = decodeFrontmatter(raw)["name"].(string)
|
||||
return name, nil
|
||||
if name, isString := decodeFrontmatter(raw)["name"].(string); isString {
|
||||
return name, nil
|
||||
}
|
||||
return literal, nil
|
||||
}
|
||||
|
||||
// isYAMLBlockIndicator returns true for YAML block scalar indicators (>, >-, >+, |, |-, |+).
|
||||
|
||||
@@ -377,6 +377,7 @@ func TestParseSkillName_ValidYAMLForms(t *testing.T) {
|
||||
"base: &n prototype\nname: *n",
|
||||
"defaults: &d {name: prototype}\n<<: *d",
|
||||
"? name\n: prototype",
|
||||
"name: \"proto\\\n type\"",
|
||||
"name: prototype\nbad: [unclosed", // not YAML: the name: line is still read
|
||||
} {
|
||||
dir, _ := writeSkill(t, []byte("---\n"+fm+"\n---\nbody\n"))
|
||||
|
||||
Reference in New Issue
Block a user