Freemarker".vars"名称不能包含破折号? [英] Freemarker ".vars" names can't contain dashes?

查看:80
本文介绍了Freemarker".vars"名称不能包含破折号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Freemarker版本2.3.16,而我刚刚在其中一个应用程序中找到了一个奇怪的错误.直到现在,我们的某些产品代码字符串中都有连字符.这些代码用于使用.vars从全局范围提取本地化文本的哈希.

We're using Freemarker version 2.3.16, and I've just tracked down a weird bug in one of our apps. It came down to there now being hyphens in some of our product code strings. The codes are used to pull hashes of localized text from the global scope using .vars.

减少问题使我举了一个任何人都可以尝试的示例:

Reducing the issue brought me to an example that anyone can try:

    模板中的
  • ${.vars["foo-bar"]}输出0

${.vars["foo+bar"]}输出nullnull

${.vars["foobar"]}正确触发InvalidReferenceException

${.vars["foobar"]} correctly triggers an InvalidReferenceException

这三个都应触发异常.相反,它似乎正在评估.vars参数字符串! :-(

All three should trigger exceptions. Instead, it appears the .vars parameter string is being evaluated! :-(

http://freemarker.sourceforge.net/docs/app_faq.html#faq_strange_variable_name 表示这应该起作用.

http://freemarker.sourceforge.net/docs/app_faq.html#faq_strange_variable_name implies this should work.

几周前,我在Freemarker邮件列表中看到类似问题的提法,建议在参数字符串前加上"@"作为前缀.这可能适用于其他哈希,但不适用于.vars.我只是举了一个有效的示例(.vars["resources_title"]),对其进行了更改,使其引发了InvalidReferenceException(.vars["@resources_title"]).我还在带连接符的引用上尝试过,它也引发了异常.

I saw mention of a similar issue a few weeks ago on the Freemarker mailing list, and it was suggested to prefix the parameter string with "@". That might work with other hashes, but it does NOT work with .vars. I just took a working example (.vars["resources_title"]) and changing it made it throw an InvalidReferenceException (.vars["@resources_title"]). I also tried it on the hyphenated reference, and it also threw the exception.

升级到2.3.18似乎没有什么作用.

Upgrading to 2.3.18 did not seem to make a difference.

推荐答案

为我工作.就像已经在自由标记用户邮件列表中提到的 :您使用了奇怪的数据模型,甚至是精美的ObjectWrapper.但是像这样的讨论可能更适合freemarker-user邮件列表...

Works for me. And like already mentioned on the freemarker-user mailing list: maybe you use a strange data model, or even a fancy ObjectWrapper. But a discussion like this is probably better suited for the freemarker-user mailing list...

这篇关于Freemarker".vars"名称不能包含破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆