Code Monkey home page Code Monkey logo

packageurl-js's People

Contributors

aniruth37 avatar chriswininger avatar darthhater avatar declanhunter avatar dependabot[bot] avatar isasmendiagus avatar jkowalleck avatar mcombuechen avatar mscudlik avatar pombredanne avatar satanshiro avatar smorimoto avatar steven-esser avatar topaztee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

packageurl-js's Issues

Qualifiers are case sensitive

The PURL test suite contains the PURL pkg:gem/[email protected]?Platform=java which is supposed to parse as having a qualifier platform=java, but packageurl-js parses it as Platform=java. This will cause problems if code uses packageurl-js to look for the value of a qualifier.

Incorrect validation of version encoding

After parsing the version number out of a PURL string, packageurl-js validates that the version number was encoded exactly the way that packageurl-js would have encoded it. This seems like an extra thing that packageurl-js does, undirected by the spec. Even if the spec did say to validate that the version number was percent encoded, that doesn't actually mean anything because technically any ASCII string that doesn't contain '%' is a valid percent encoded string by definition.

This is problematic because different PURL implementations encode different sets of characters. If a version number contains a character that one PURL implementation unnecessary escapes and packageurl-js does not, or vice versa, packageurl-js will correctly parse the version number and then throw an exception because the encoding validation failed. For example, packageurl-js will fail to decode this valid PURL produced by packageurl-java: pkg:t/n@1%3A2.

have license texts not stripped by builders/packers/transpilers

in the JavaScript/node ecosystem, it is common to pack/transpile/transform source code for a target system.
babel, webpack, esbuild, ... these tools are usually used for the tasks.

tools minify code by stripping comments.
a license-text-comment should not be stripped, but it should be kept.
therefore these tools do not touch block-comments that start with /*!. some tools replace these comments with a text that states in which file the original text can still be found. yet they respect the ! and keep the texts.

task: make all license-text comments be block-comments starting with an enforcer-mark !

Incorrect purl with multiple forward slashes in namespace

An incorrect purl is generated when call toString() in a PackageURL object with those parameters:

    "type": "golang",
    "namespace": "github.com/cncf/xds",
    "name": "go",
    "version": "v0.0.0-20210922020428-25de7278fc84"

Instead of getting the correct purl: pkg:golang/github.com/cncf/xds/[email protected]
An encoded slash is generated in the namespace

purl containing a query parameter repository_url with own (encoded) query parameters not handled correctly?

Hi there,

...maybe this is just misunderstanding from my side, but when I create a purl object for a purl like this
pkg:oci/azure-cli@sha256:9df8ac260650dbae684ab7e47916d4def942582b491d1fe0593b22eb1cac235b?repository_url=index.docker.io%2Fbitnami%2Fazure-cli\u0026arch=amd64
it seems that the (encoded) query parameter from the query parameter repository_url is handled as separate query parameter of the purl and not of the repository_url.
The result is:

PackageURL {
      type: 'oci',
      name: 'azure-cli',
      namespace: null,
      version: 'sha256:9df8ac260650dbae684ab7e47916d4def942582b491d1fe0593b22eb1cac235b',
      qualifiers: {
        repository_url: 'index.docker.io/bitnami/azure-cli',
        arch: 'amd64'
      },
      subpath: null
    }

My expectation would have been:

PackageURL {
      type: 'oci',
      name: 'azure-cli',
      namespace: null,
      version: 'sha256:9df8ac260650dbae684ab7e47916d4def942582b491d1fe0593b22eb1cac235b',
      qualifiers: {
        repository_url: 'index.docker.io/bitnami/azure-cli&arch=amd64'
      },
      subpath: null
    }

Is my expectation wrong or is this a bug?

Handle qualifiers with a string value

Currently we throw an exception when creating a packageURL with qualifiers that are strings.

The python version currently handles this, so the JS version should as well.

fromString(): version is used outside of block scope

In method fromString() the version variable is used in line 147 to construct a new object,
but the variable is declared with a block scope inside an if statement (line 123).

This is an issue when using packageurl-js from typescript:
https://www.typescriptlang.org/docs/handbook/variable-declarations.html#block-scoping

As a consequence, fromString() always throws an error using typescript:

message:"version is not defined"
stack:"ReferenceError: version is not defined

Incorrect parsing of PURLs begining with `pkg://`

The PURL test suite contains the PURL pkg://maven/org.apache.commons/io which is supposed to parse as a namespace of org.apache.commons and a name of io, but packageurl-js parses it as having no namespace. The namespace just disappears. It doesn't become part of the name.

TypeScript: type-definitions missing

There are currently no type definitions for TypeScript available.
Since TypeScript is becoming more and more popular it would be great to have them.

[PROJECT] release version 1.x.x

currently the versioning of this library is 0.0.x.
This library is distributed via https://npmjs.org - therefore semantic versioning is enforced by all consuming dependency management systems.

The problem i see: according to semantic versioning each version of 0.0.x is identified as a breaking change.
This means: projects that require this very library usually do this via ^0.0.x - so if they depend on ^0.0.1 they are incompatible to any later version - dependency management tools will not install it because ^0.0.1 conflicts with 0.0.6 and this conflicts with 0.0.7
This means: projects that use multiple downstream libraries that require different versions of this library wlll force pnpm, yarn, npm and others package managers to fail (or install multiple different versions to be installed). This leads to a dependency mess.

See some example downstream usage:

solution: Just release a 1.x.x version.
This library will never be feature complete, because PackageURL is a living standard that is never complete. SO keeping a 0.x.x or even 0.0.x version strategy is an unnecessary obstruction.
Releasing a major version would enable you to finally use proper semantic versioning with major(breaking) , minor(feature) and patch(bugfix) sub versioning.

see also NPM's version tester, to experience the impact : https://semver.npmjs.com/

Invalid purl passes as valid

PURL - 'pkg:maven/org.apache.commons:[email protected]' passes as valid

p.PackageURL.fromString('pkg:maven/org.apache.commons:[email protected]')
PackageURL {
type: 'maven',
name: 'org.apache.commons:io',
namespace: null,
version: '1.3.4',
qualifiers: null,
subpath: null
}

However, it shouldn't be because the namespace is not percent-encoded.

Invalid purl: version must be percent-encoded

Hi, I encounter this error: Invalid purl: version must be percent-encoded when parse the purl pkg:npm/@vue/[email protected] with method PackageURL.fromString().
This purl was validated successfully by other library mvn:[email protected] in the backend.

When I look into the code of packageurl-js, I see this:

if (p.includes('@')) {
    let f = p.indexOf('@'),
      u = p.substring(f + 1)
    a = decodeURIComponent(u)
    let y = encodeURIComponent(a).replace(/%3A/g, ':').replace(/%2B/g, '+')
    if (u !== y)
      throw new Error('Invalid purl: version must be percent-encoded')
    i = p.substring(0, f)
}

I think it could have an issue because method indexOf() return the first matched index, but in this case pkg:npm/@vue/[email protected], it has another @ so f+1 is not the start of version substring.

Incorrect validation of qualifier keys

The spec is a little redundant, but here are the important things it says about qualifier keys:

  • "must be composed only of ASCII letters and numbers, '.', '-' and '_' (period, dash and underscore)"
  • "cannot start with a number"
  • "case insensitive"

packageurl-js implements this using the expression /^[a-z]+$/i.test(key) || /[\.-_]/.test(key) (negated and simplified to make this easier to describe).

  • The regular expression (?i)^[a-z]+$ matches for any string which is entirely letters. We'll call this subexpression allLetters.
  • The regular expression [\.-_] matches any ASCII character value between '.' and '_', which includes '/', numbers, '=', etc but doesn't include '-'. This seems like it was meant to be [\.\-_], which matches the three characters that are called out in the spec. We'll call this corrected subexpression containsAllowedSpecial.

Substituting in those names, we get the expression allLetters || containsAllowedSpecial for determining if a qualifier key is valid. Even with the corrected regular expression, this does not match the spec. a1 is invalid because it contains a number, but it should be valid. _! is valid because it contains '_', but it should be invalid because '!' is not an allowed character.

I found this because with the incorrect regular expression, x- prefixed qualifiers are incorrectly considered to be invalid.

Parts of purls that should be percent-encoded are not correctly encoded

I've been working on some issues for cdxgen with generating Gradle purls for projects. My issue is that Gradle prefixes project names with a ':', which should imho not be an issue if the name would actually be percent-encoded. I noticed during testing however, that this is not the case.

Checking your code, you do actually use encodeURIComponent, but then explicitly turn '%3A' back into ':'. When I then feed the generated purl into your fromString-method to validate it, it fails, because of the ':' in the purl:

let [scheme, remainder] = purl.split(':', 2);

Now, for a top-level project in Gradle, I could remove the ':', but then the question becomes how to handle sub-projects. These have the ':' not just at the front, but inbetween the layered projects as well (eg. :a:b:c:d). Currently, cdxgen removes the initial ':' and changes the remaining ':' to a '/', which unfortunately with the way your code works, makes all parts before the last '/' part of the namespace! This could then generate a purl that identifies multiple projects, eg:

  • Namespace 'a/b/c', name 'd' --> purl: 'a/b/c/d'
  • Namespace 'a/b', name ':c:d' --> purl 'a/b/c/d'

I would expect when using a name like :a:b, to get a purl looking more or less like pkg:maven/namespace/%3Aa%3Ab@version.

In case the current behavior is not an error, but actually expected, I think there is need for a discussion about how to make purls for Gradle (in case there hasn't already been one).

Also, in case this is an error, there's more places in your code where specific characters are explicitly decoded -- maybe worth taking a look at those as well...

Not all underscores are replaced with dashes for PyPi packages

Hello.

We have used the library and it works good for us in most of cases.

But we noticed the following issue: according to the pURL specification, for PyPi packages all underscores "_" must be replaced with dashes "-" in the name. However, it seems as if only the first occurrence is replaced using "someString.replace(...)".

Can you please have a look at this?
(There are also other usages of replace function.)

Thank you very much,
Pavel

purls with + in versions are not accepted

Any of the following purls will fail in the latest version
pkg:pypi/[email protected]+cpu
pkg:deb/debian/[email protected]+deb9u1?arch=amd64&upstream=gettext&distro=debian-9
pkg:deb/debian/libprocps3@2:3.3.9-9+deb8u1?arch=amd64&upstream=procps&distro=debian-8
pkg:deb/debian/[email protected]+deb10u3?arch=amd64&upstream=openssl&distro=debian-10

any purl that has a plus sign will fail with the error:
Invalid purl: version must be percent-encoded

Package types are case sensitive

The PURL test suite contains a PURL pkg:PYPI/[email protected]. packageurl-js parses this as type PYPI instead of the expected pypi.

This causes two problems:

  1. Code that is looking for pypi PURLs won't see them.
  2. The pypi-specific name normalization rules that packageurl-js implements for pypi are not applied, so the package name comes out as Django_package instead of the expected django-package.

Readme could use some examples

The readme document does not yet show any usage examples to help developers use this.

I've created a pull request which I hope will help with this #24.

Let me know if this works for you all.

Thx Much :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.