commit
2ea963bd5a
@ -0,0 +1,31 @@ |
||||
/** |
||||
* @jest-environment jsdom |
||||
*/ |
||||
|
||||
import { searchEngine } from '../../js/lib/autocomplete' |
||||
|
||||
test('searchEngine', () => { |
||||
expect(searchEngine('qwe', { |
||||
'name': 'Test', |
||||
'symbol': 'TST', |
||||
'address_hash': '0x000', |
||||
'tx_hash': '0x000', |
||||
'block_hash': '0x000' |
||||
})).toEqual(undefined) |
||||
|
||||
expect(searchEngine('tes', { |
||||
'name': 'Test', |
||||
'symbol': 'TST', |
||||
'address_hash': '0x000', |
||||
'tx_hash': '0x000', |
||||
'block_hash': '0x000' |
||||
})).toEqual('<div><div>0x000</div><div><b><mark class=\'autoComplete_highlight\'>Tes</mark>t</b> (TST)</div></div>') |
||||
|
||||
expect(searchEngine('qwe', { |
||||
'name': 'qwe1\'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{\'7\'*\'7\'}}', |
||||
'symbol': 'qwe1\'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{\'7\'*\'7\'}}', |
||||
'address_hash': '0x000', |
||||
'tx_hash': '0x000', |
||||
'block_hash': '0x000' |
||||
})).toEqual('<div><div>0x000</div><div><b><mark class=\'autoComplete_highlight\'>qwe</mark>1'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}}</b> (<mark class=\'autoComplete_highlight\'>qwe</mark>1'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}})</div></div>') |
||||
}) |
@ -0,0 +1,12 @@ |
||||
/** |
||||
* @jest-environment jsdom |
||||
*/ |
||||
|
||||
import { escapeHtml } from '../../js/lib/utils' |
||||
|
||||
test('escapeHtml', () => { |
||||
expect(escapeHtml('<script>')).toEqual('<script>') |
||||
expect(escapeHtml('1&')).toEqual('1&') |
||||
expect(escapeHtml('1"')).toEqual('1"') |
||||
expect(escapeHtml('1\'')).toEqual('1'') |
||||
}) |
@ -0,0 +1,44 @@ |
||||
defmodule BlockScoutWeb.SearchViewTest do |
||||
use ExUnit.Case |
||||
alias BlockScoutWeb.SearchView |
||||
|
||||
test "highlight_search_result/2 returns search result if query doesn't match" do |
||||
query = "test" |
||||
search_result = "qwerty" |
||||
res = SearchView.highlight_search_result(search_result, query) |
||||
IO.inspect(res) |
||||
|
||||
assert res == {:safe, search_result} |
||||
end |
||||
|
||||
test "highlight_search_result/2 returns safe HTML of unsafe search result if query doesn't match" do |
||||
query = "test" |
||||
search_result = "qwe1'\"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}}" |
||||
res = SearchView.highlight_search_result(search_result, query) |
||||
IO.inspect(res) |
||||
|
||||
assert res == |
||||
{:safe, |
||||
"qwe1'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}}"} |
||||
end |
||||
|
||||
test "highlight_search_result/2 returns highlighted search result if query matches" do |
||||
query = "qwe" |
||||
search_result = "qwerty" |
||||
res = SearchView.highlight_search_result(search_result, query) |
||||
IO.inspect(res) |
||||
|
||||
assert res == {:safe, "<mark class='autoComplete_highlight'>qwe</mark>rty"} |
||||
end |
||||
|
||||
test "highlight_search_result/2 returns highlighted safe HTML of unsafe search result if query match" do |
||||
query = "qwe" |
||||
search_result = "qwe1'\"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}}" |
||||
res = SearchView.highlight_search_result(search_result, query) |
||||
IO.inspect(res) |
||||
|
||||
assert res == |
||||
{:safe, |
||||
"<mark class='autoComplete_highlight'>qwe</mark>1'"><iframe/onload=console.log(123)>${7*7}{{7*7}}{{'7'*'7'}}"} |
||||
end |
||||
end |
Loading…
Reference in new issue