Skip to content

Commit 407864f

Browse files
committed
Escape property keys when creating table view
1 parent 96a7f79 commit 407864f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

app/scripts/directives/neoTable.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ angular.module('neo4jApp.directives')
3535
json2html = (obj) ->
3636
return emptyMarker() unless Object.keys(obj).length
3737
html = "<table class='json-object'><tbody>"
38-
html += "<tr><th>#{k}</th><td>#{cell2html(v)}</td></tr>" for own k, v of obj
38+
html += "<tr><th>#{Utils.escapeHTML(k)}</th><td>#{cell2html(v)}</td></tr>" for own k, v of obj
3939
html += "</tbody></table>"
4040
html
4141

@@ -59,7 +59,7 @@ angular.module('neo4jApp.directives')
5959
html = "<table class='table data'>"
6060
html += "<thead><tr>"
6161
for col in cols
62-
html += "<th>#{col}</th>"
62+
html += "<th>#{Utils.escapeHTML(col)}</th>"
6363
html += "</tr></thead>"
6464
html += "<tbody>"
6565
if result.displayedSize

test/spec/directives/neoTable.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,36 @@ describe 'Directive: neoTable', () ->
3333
columns: -> ['col']
3434
scope.$apply()
3535
expect(element.html()).toContain('&lt;script&gt;')
36+
37+
it 'should escape HTML characters in column name', inject ($rootScope, $compile) ->
38+
scope = $rootScope.$new()
39+
element = angular.element '<neo-table table-data="val"></neo-table>'
40+
element = $compile(element)(scope)
41+
scope.val =
42+
rows: -> [[]]
43+
displayedSize: 1
44+
columns: -> ['<p>']
45+
scope.$apply()
46+
expect(element.html()).toContain('&lt;p&gt;')
47+
48+
it 'should escape HTML characters in property name', inject ($rootScope, $compile) ->
49+
scope = $rootScope.$new()
50+
element = angular.element '<neo-table table-data="val"></neo-table>'
51+
element = $compile(element)(scope)
52+
scope.val =
53+
rows: -> [[{'<p>':'value'}]]
54+
displayedSize: 1
55+
columns: -> ['col']
56+
scope.$apply()
57+
expect(element.html()).toContain('&lt;p&gt;')
58+
59+
it 'should escape HTML characters in property value', inject ($rootScope, $compile) ->
60+
scope = $rootScope.$new()
61+
element = angular.element '<neo-table table-data="val"></neo-table>'
62+
element = $compile(element)(scope)
63+
scope.val =
64+
rows: -> [[{'key':'<p>'}]]
65+
displayedSize: 1
66+
columns: -> ['col']
67+
scope.$apply()
68+
expect(element.html()).toContain('&lt;p&gt;')

0 commit comments

Comments
 (0)