Skip to content

Commit

Permalink
fix(pnpm): workaround for yaml.v3 question-mark in inline object
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki-working committed Apr 11, 2024
1 parent fe4091c commit cc94465
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 10 additions & 0 deletions module/pnpm/shared/yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package shared

import (
"bytes"
"gopkg.in/yaml.v3"
)

func ParseYaml(data []byte, target any) error {
return yaml.Unmarshal(bytes.ReplaceAll(data, []byte{'?'}, []byte("(QuestionMark)")), target)
}
4 changes: 1 addition & 3 deletions module/pnpm/v5/v5.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package v5

import (
"bytes"
"github.com/murphysecurity/murphysec/model"
"github.com/murphysecurity/murphysec/module/pnpm/shared"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -151,7 +149,7 @@ func (c *circleDetector) With(name, version string) *circleDetector {
func ParseLockfile(data []byte) (*Lockfile, error) {
var lockfile Lockfile
// workaround for unquoted question-mark in inline object
if e := yaml.Unmarshal(bytes.ReplaceAll(data, []byte{'?'}, []byte("(QuestionMark)")), &lockfile); e != nil {
if e := shared.ParseYaml(data, &lockfile); e != nil {
return nil, e
}
lockfile.buildIndexes()
Expand Down
4 changes: 2 additions & 2 deletions module/pnpm/version_indicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pnpm

import (
"fmt"
"gopkg.in/yaml.v3"
"github.com/murphysecurity/murphysec/module/pnpm/shared"
"regexp"
)

Expand All @@ -12,7 +12,7 @@ type lockfileVersionIndicator struct {

func parseLockfileVersion(data []byte) (string, error) {
var indicator lockfileVersionIndicator
if e := yaml.Unmarshal(data, &indicator); e != nil {
if e := shared.ParseYaml(data, &indicator); e != nil {
return "", fmt.Errorf("parseLockfileVersion: %w", e)
}
return indicator.LockfileVersion, nil
Expand Down

0 comments on commit cc94465

Please sign in to comment.