Skip to content

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

@pvgoran

Description

@pvgoran

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions