Skip to content

Serializer checkIntegrity broken by constructor and setPrefix #743

Description

@DJ1TJOO

The checkIntegrity() will always throw an error because of the invalid initiation. solidNs() can have multiple prefixes for the same uri breaking the integrity.

const nsKeys = Object.keys(solidNs())
for (const i in nsKeys) {
const uri = solidNs()[nsKeys[i]]('')
const prefix = nsKeys[i]
this.prefixes[uri] = prefix
this.namespaces[prefix] = uri
}

Currently it will always have the last prefix for a specific uri in the prefixes object, and all variants in the namespaces object. However, when serializing only the prefixes object is used to convert uri to prefixes, so the other variants in the namespaces object will never be touched.

To solve it I think suggestPrefix should be used, this will make sure the integrity is kept, and instead of using the last prefix of the solidNs() it will use the first one.

The setPrefix should, then also delete the old value in the namespace object to keep the integrity, this does not effect the functionality of the serializer, it only may make it a bit slower

rdflib.js/src/serializer.js

Lines 104 to 108 in 1b386c4

// remove any existing prefix targeting this uri
// for (let existingPrefix in this.namespaces) {
// if (this.namespaces[existingPrefix] == uri)
// delete this.namespaces[existingPrefix];
// }

I will make this change in fase-3 of my refactor of the serializer #740

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