metafacture / metafacture-fix

Work in progress towards an implementation of the Fix language for Metafacture
Apache License 2.0
6 stars 2 forks source link

`replace_all` with alternation expects multiple matching path, breaks with single matching path #249

Open TobiasNx opened 2 years ago

TobiasNx commented 2 years ago

Input:

{
  "describedBy" : {
    "type" : [ "BibliographicDescription" ],
    "dateCreated" : "20220711"
  }
}

FIX: replace_all("describedBy.dateCreated|dateModified","2","?")

Expected:

{
  "describedBy" : {
    "type" : [ "BibliographicDescription" ],
    "dateCreated" : "?0??0711"
  }
}

Results in Error:

org.metafacture.metafix.FixExecutionException: Error while executing Fix expression (at file:/tmp/metafix5253049504537349638.fix, line 1): replace_all("describedBy.dateCreated|dateModified","2","?")
...
Caused by: java.lang.IllegalStateException: Expected Array or Hash, got String

See in Playground here.

Multiple Path work, see here.

blackwinter commented 2 years ago

replace_all("describedBy.dateCreated|dateModified","2","?")

Just to be extra clear: Any other potential bugs notwithstanding, I would strongly advise against relying on this wrong behaviour in the current Metafix implementation! See #143.

TobiasNx commented 2 years ago

This also breaks with "flat" alteration. replace_all("dateCreated|dateModified","2","?")

https://metafacture.org/playground/?flux=PG_DATA%0A%7C+as-records%0A%7C+decode-json%0A%7C+fix%0A%7C+encode-json%28prettyPrinting%3D%22true%22%29%0A%7C+print%0A%3B&fix=replace_all%28%22dateCreated%7CdateModified%22%2C%222%22%2C%22%3F%22%29%0A&data=%7B%0A++++%22type%22+%3A+%5B+%22BibliographicDescription%22+%5D%2C%0A++++%22dateCreated%22+%3A+%2220220711%22%0A%7D&active-editor=fix

PS: We went with separate replace_all functions to circumvent this problem.

blackwinter commented 2 years ago

This also breaks with "flat" alteration. replace_all("dateCreated|dateModified","2","?")

Good. Then we should focus on that.