33import frappe
44import requests
55from frappe import _
6+ from frappe .utils import escape_html
67from lxml import etree
78
89URL_PREFIXES = ("http://" , "https://" )
@@ -32,7 +33,12 @@ def import_genericode():
3233 content = f .read ()
3334
3435 # Parse the xml content
35- parser = etree .XMLParser (remove_blank_text = True )
36+ parser = etree .XMLParser (
37+ remove_blank_text = True ,
38+ resolve_entities = False ,
39+ load_dtd = False ,
40+ no_network = True ,
41+ )
3642 try :
3743 root = etree .fromstring (content , parser = parser )
3844 except Exception as e :
@@ -104,15 +110,15 @@ def get_genericode_columns_and_examples(root):
104110
105111 # Get column names
106112 for column in root .findall (".//Column" ):
107- column_id = column .get ("Id" )
113+ column_id = escape_html ( column .get ("Id" ) )
108114 columns .append (column_id )
109115 example_values [column_id ] = []
110116 filterable_columns [column_id ] = set ()
111117
112118 # Get all values and count unique occurrences
113119 for row in root .findall (".//SimpleCodeList/Row" ):
114120 for value in row .findall ("Value" ):
115- column_id = value .get ("ColumnRef" )
121+ column_id = escape_html ( value .get ("ColumnRef" ) )
116122 if column_id not in columns :
117123 # Handle undeclared column
118124 columns .append (column_id )
@@ -123,7 +129,7 @@ def get_genericode_columns_and_examples(root):
123129 if simple_value is None :
124130 continue
125131
126- filterable_columns [column_id ].add (simple_value .text )
132+ filterable_columns [column_id ].add (escape_html ( simple_value .text ) )
127133
128134 # Get example values (up to 3) and filter columns with cardinality <= 5
129135 for row in root .findall (".//SimpleCodeList/Row" )[:3 ]:
@@ -133,7 +139,7 @@ def get_genericode_columns_and_examples(root):
133139 if simple_value is None :
134140 continue
135141
136- example_values [column_id ].append (simple_value .text )
142+ example_values [column_id ].append (escape_html ( simple_value .text ) )
137143
138144 filterable_columns = {k : list (v ) for k , v in filterable_columns .items () if len (v ) <= 5 }
139145
0 commit comments