Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering the same custom function twice does not work #398

Open
rrthomas opened this issue Jul 21, 2021 · 2 comments
Open

Registering the same custom function twice does not work #398

rrthomas opened this issue Jul 21, 2021 · 2 comments

Comments

@rrthomas
Copy link
Contributor

Example code:

import {evaluateXPathToString, registerCustomXPathFunction, Options} from 'fontoxpath'

const foo = 'https://example.org/foo.dtd'


registerCustomXPathFunction(
  {localName: 'foo', namespaceURI: foo},
  ['xs:string'], 'xs:string', (_, arg: string) => {
    return arg
  }
)

registerCustomXPathFunction(
  {localName: 'foo', namespaceURI: foo},
  ['xs:string'], 'xs:string', (_, arg: string) => {
    return `${arg}bar`
  }
)

const URI_BY_PREFIX: {[key: string]: string} = {foo}

const xQueryOptions: Options = {
  namespaceResolver: (prefix: string) => URI_BY_PREFIX[prefix],
}

console.log(evaluateXPathToString('foo:foo("foo")', null, null, null, xQueryOptions))

Expected output: foobar. Actual output: foo. Tested with 3.19.0.

@devatwork
Copy link
Contributor

Thanks for reporting @rrthomas! Out of intrest, do you have a use case for "overwriting" an existing function?

Arguably, the 2nd call to registerCustomXPathFunction should have thrown.

@rrthomas
Copy link
Contributor Author

My use was a custom function with a hidden variable that is set in the context. Originally, that variable was a normal TypeScript value, which meant that I wanted to re-register the function, which didn't work. I worked around the limitation by instead making the hidden variable an object property, which I could then update without re-registering the function. So it's not essential to me, no. It would be good if I had got an error rather than the re-registering being silently ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants