Skip to content

Commit 711487f

Browse files
committed
Merge pull request #180 from pe4cey/escape-property-keys
Escape property keys when creating table view
2 parents ce59c42 + 407864f commit 711487f

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
@@ -36,7 +36,7 @@ angular.module('neo4jApp.directives')
3636
json2html = (obj) ->
3737
return emptyMarker() unless Object.keys(obj).length
3838
html = "<table class='json-object'><tbody>"
39-
html += "<tr><th>#{k}</th><td>#{cell2html(v)}</td></tr>" for own k, v of obj
39+
html += "<tr><th>#{Utils.escapeHTML(k)}</th><td>#{cell2html(v)}</td></tr>" for own k, v of obj
4040
html += "</tbody></table>"
4141
html
4242

@@ -62,7 +62,7 @@ angular.module('neo4jApp.directives')
6262
html = "<table class='table data'>"
6363
html += "<thead><tr>"
6464
for col in cols
65-
html += "<th>#{col}</th>"
65+
html += "<th>#{Utils.escapeHTML(col)}</th>"
6666
html += "</tr></thead>"
6767
html += "<tbody>"
6868
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)