Skip to content

Discrepancy between vex.Open and vex.Parse #55

Open
@knqyf263

Description

@knqyf263

vex.Parse assums the latest version.

// Parse parses an OpenVEX document in the latest version from the data byte array.
func Parse(data []byte) (*VEX, error) {
vexDoc := &VEX{}
if err := json.Unmarshal(data, vexDoc); err != nil {
return nil, fmt.Errorf("%s: %w", errMsgParse, err)
}
return vexDoc, nil
}

vex.Open autodetects the version.

if documentContextLocator == ContextLocator() {
return Parse(data)
} else if documentContextLocator != "" {
version := strings.TrimPrefix(documentContextLocator, Context)
version = strings.TrimPrefix(version, "/")

At first, I tried vex.Open, and my VEX file didn't work because the @context in the file was "https://openvex.dev/ns/ even though the file content was compatible with v0.2.0. Then, Open fell back into v0.0.1.

But after I switched to vex.Parse, it suddenly worked. I was a bit surprised they behaved differently. Is it possible to change both to the same behavior? I'd like to know the reason if it is intentional. If you agree to the change, I can open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions