简体   繁体   中英

escaping quotes in grails gsp for es

Hi guys I'm trying to escape double quotation marks in my gsp search query which is being passed into elasticsearch so far I have:

<input id="q" name="q" type="text" class="large" value="${params?.q?.encodeAsHTML()}" ..

But when I go to my webapps search field and use a query something like "abc" i get massive exceptions in my logfile, mainly:

 org.apache.lucene.queryParser.ParseException: Cannot parse '("abc) AND recstatus:"public"': Lexical error at line 1, column 30.  Encountered: <EOF> after : ""

and

2013-03-01 11:35:06,874 [New I/O  worker #3] DEBUG search.type  - [Helleyes] [some_index][3], node[BZH5bHO8RX2va-HVpTDEng], [P], s[STARTED]: Failed to execute 
[org.elasticsearch.action.search.SearchRequest@2f6a3595]
org.elasticsearch.transport.RemoteTransportException: [Lasher][inet[/xxx.xxx.x.xxx:9300]][search/phase/query]
Caused by: org.elasticsearch.search.SearchParseException: [some_index][3]: from[0],size[20]: Parse Failure [Failed to parse source [:)
^E򃦲om@0<83>sizeA20<84>query򋱵ery_string򂜨"abc) AND recstatus:"public"<8f>analyze_wildcard#󻅦ields䴩tle񻀁]]

etc.. any suggestions?

Found the problem...

in config.groovy there's a flag set:

grails.views.default.codec = "none"

and this overrides any code in the gsp pages.

you can either set this flag to:

grails.views.default.codec = "html"

or override individual gsp files.

或者最好使用Grails 2.3+ http://mrhaki.blogspot.com.es/2013/11/grails-goodness-generating-raw-output.html ;)中的raw()方法

<li${raw(' class="active"')}/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM