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

TemplateSource's need better, stricter equals() #686

Open
pvgoran opened this issue Feb 21, 2019 · 1 comment · May be fixed by #944
Open

TemplateSource's need better, stricter equals() #686

pvgoran opened this issue Feb 21, 2019 · 1 comment · May be fixed by #944

Comments

@pvgoran
Copy link
Contributor

pvgoran commented Feb 21, 2019

Most TemplateSource implementations inherit equals() from AbstractTemplateSource which only compares filename().

This means that two equally named TemplateSource's, even loaded from different media (ClassPath, filesystem, Internet, whatever), will be considered identical by the template cache system, which can cause caching false positives. So probably URLTemplateSource should be considered equal only to another URLTemplateSource with the same location (not name!).

StringTemplateSource is a place where this problem can surface even without using different template loaders and fancy stuff like that. It gets its filename from the constructor parameter; in Handlebars.compileInline(), the name passed to the constructor is derived from the template string's hashCode(). In case of hash code collision, two different template strings will have the same filename in StringTemplateSource and will thus be considered equal by the cache system, which will yield the same Template for two different template strings. A totally unexpected, rare, and thus hard to catch failure. StringTemplateSource must compare content, not filename!

@minzcmu
Copy link

minzcmu commented Jun 12, 2020

Got hit by this issues recently! Currently the equals() only compares the filename.
should definitely compare content if the filename is the same for StringTemplateSource. It's easily to hit collision when having a lot strings.

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