Show HTML in search results.

master
Pacman Ghost 4 years ago
parent b4571800ad
commit 7ac1119191
  1. 8
      asl_articles/search.py
  2. 38
      asl_articles/tests/test_search.py

@ -13,7 +13,7 @@ from asl_articles.models import Publisher, Publication, Article, Author, Scenari
from asl_articles.publishers import get_publisher_vals
from asl_articles.publications import get_publication_vals
from asl_articles.articles import get_article_vals
from asl_articles.utils import clean_html, decode_tags, to_bool
from asl_articles.utils import decode_tags, to_bool
_search_index_path = None
_logger = logging.getLogger( "search" )
@ -309,10 +309,8 @@ def _do_add_or_update_searchable( dbconn, owner_type, owner, obj ):
f: getattr( obj,fields[f] ) if isinstance( fields[f], str ) else fields[f]( obj )
for f in fields
}
vals = {
k: clean_html( v, allow_tags=[], safe_attrs=[] )
for k,v in vals.items()
}
# NOTE: We used to strip HTML here, but we prefer to see formatted content
# when search results are presented to the user.
def do_add_or_update( dbconn ):
dbconn.conn.execute( "INSERT INTO searchable"

@ -1,6 +1,6 @@
""" Test search operations. """
from asl_articles.search import SearchDbConn, _make_fts_query_string
from asl_articles.search import _make_fts_query_string
from asl_articles.tests.test_publishers import create_publisher, edit_publisher
from asl_articles.tests.test_publications import create_publication, edit_publication
@ -271,42 +271,6 @@ def test_highlighting( webdriver, flask_app, dbconn ):
# ---------------------------------------------------------------------
def test_html_stripping( webdriver, flask_app, dbconn ):
"""Test HTML stripping of searchable content."""
# initialize
init_tests( webdriver, flask_app, dbconn )
# create objects with HTML content
create_publisher( {
"name": "A <b>bold</b> publisher",
"description": "This is some <b>bold text</b>, this is <i>italic</i>."
} )
create_publication( {
"name": "A <b>bold</b> publication",
"edition": "75<u>L</u>",
"description": "This is some <b>bold text</b>, this is <i>italic</i>.",
"tags": [ "+<b>bold</b>", "+<i>italic</i>" ]
}, toast_type="warning" )
create_article( {
"title": "An <i>italic</i> article",
"subtitle": "A <b>bold</b> subtitle",
"authors": [ "+Joe <u>Underlined</u>" ],
"tags": [ "+<b>bold</b>", "+<i>italic</i>" ],
"scenarios": [ "+<b>bold</b> [B1]", "+<i>italic</i> [I1]" ],
"snippet": "This is some <b>bold text</b>, this is <i>italic</i>."
}, toast_type="warning" )
# check if the search index contains any HTML
def is_html_clean( val ):
return "<" not in val and ">" not in val if val else True
with SearchDbConn() as dbconn2:
curs = dbconn2.conn.execute( "SELECT * FROM searchable" )
for row in curs:
assert all( is_html_clean(v) for v in row )
# ---------------------------------------------------------------------
def test_make_fts_query_string():
"""Test generating FTS query strings."""

Loading…
Cancel
Save