sandstone-mc / sandstone

Sandstone | Next Generation Framework for Minecraft
https://sandstone.dev/
MIT License
174 stars 15 forks source link

Incorrect base path template tag implementation #109

Open GrantGryczan opened 2 years ago

GrantGryczan commented 2 years ago

BasePathClass.prototype.getResourceName does not accept substitutions like template tags normally do. It only looks at the template parts of the inputted string.

image

name.join() is the part of the code below causing this issue, in addition to the incorrect parameter types.

https://github.com/TheMrZZ/sandstone/blob/35291b3695f026c06e7bd63d6e9abc53d97c6598/src/datapack/BasePath.ts#L170

The correct signature of a template tag function should be this:

(template: TemplateStringsArray, ...substitutions: any[]) => string

Otherwise, for example, basePath`a${b}c` will output the same thing as basePath`ac` (or actually basePath`a,c` since it's name.join() and not name.join('')) no matter what b is.

Here is an example of a correct implementation for a template tag function which simply outputs exactly the string which is inputted:

(template, ...substitutions) => (
    template.map((string, i) => string + (i in substitutions ? substitutions[i] : '')).join('')
)