Index: branches/wmf/1.18wmf1/extensions/MobileFrontend/javascripts/opensearch.js |
— | — | @@ -144,20 +144,30 @@ |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
| 148 | +function htmlEntities( str ) { |
| 149 | + return String( str ).replace( /&/g, '&' ).replace( /</g, '<' ).replace( />/g, '>' ).replace( /"/g, '"' ).replace( /'/g, ''' ); |
| 150 | +} |
| 151 | + |
| 152 | +function escapeJsString( str ) { |
| 153 | + return String( str ).replace( /\\/g, '\\\\' ).replace( /'/g, "\\'" ).replace( /\n/g, '\\n' ); |
| 154 | +} |
| 155 | + |
148 | 156 | function writeResults( sections ) { |
149 | 157 | results.style.display = 'block'; |
150 | 158 | if ( !sections || sections.length < 1 ) { |
151 | 159 | results.innerHTML = "No results"; |
152 | | - } else { |
| 160 | + } else { |
153 | 161 | var html = '<div class="suggestions-results">'; |
154 | 162 | for ( i = 0; i < sections.length; i++ ) { |
155 | 163 | var section = sections[i]; |
156 | 164 | var rel = i + 1; |
157 | 165 | section.value = section.value.replace( /^(?:\/\/|[^\/]+)*\//, '/' ); |
158 | | - html = html + "<div class=\"suggestions-result\" rel=\"" + rel + "\" title=\"" + section.label + "\"><a class=\"sq-val-update\" href=\"javascript:sqValUpdate('" + section.label + "');\">+</a><a class=\"search-result-item\" href='" + section.value + "'>" + section.label + "</a></div>"; |
| 166 | + console.log(htmlEntities(escapeJsString( section.label))); |
| 167 | + html = html + "<div class=\"suggestions-result\" rel=\"" + htmlEntities( rel ) + "\" title=\"" + htmlEntities( section.label ) + "\"><a class=\"sq-val-update\" href=\"javascript:sqValUpdate('" + htmlEntities( escapeJsString( section.label ) ) + "');\">+</a><a class=\"search-result-item\" href='" + htmlEntities( section.value ) + "'>" + htmlEntities( section.label ) + "</a></div>"; |
159 | 168 | if ( i < ( sections.length - 1 ) ) { |
160 | 169 | html = html + '<hr />'; |
161 | 170 | } |
| 171 | + console.log(html); |
162 | 172 | } |
163 | 173 | html = html + '</div>'; |
164 | 174 | results.innerHTML = html; |