Skip to content

Commit

Permalink
Remove octicons altogether from gollum-lib. (#441)
Browse files Browse the repository at this point in the history
* Remove octicons altogether from gollum-lib.
* Rename Octicon macro to Icon. Leave finding and rendering the actual icon to frontend (gollum).
* Remove hardcoded octicon names from gollum-lib.
* Add Flash macro that comes without default icon.
* Upgrade minitest-reporters.
  • Loading branch information
bartkamphorst authored and Dawa Ometto committed Aug 1, 2023
1 parent e144af1 commit 63dd863
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 48 deletions.
3 changes: 0 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

* Bugfix release: address XSS vulnerability ( @6661620a, @dometto)


# 5.2.3 / 2023-03-13

* Bugfix release: update adapter dependencies for Ruby 3.2 support.



# 5.2.2 / 2023-01-18

* Bugfix release: set Nokogiri default XHTML conversion options more relaibly. See https://github.com/sparklemotion/nokogiri/issues/2761
Expand Down
5 changes: 2 additions & 3 deletions gemspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def specification(version, default_adapter, platform = nil)
s.add_dependency 'loofah', '~> 2.3'
s.add_dependency 'github-markup', '~> 4.0'
s.add_dependency 'gemojione', '~> 4.1'
s.add_dependency 'octicons', '~> 17.0'
s.add_dependency 'twitter-text', '1.14.7'

s.add_development_dependency 'org-ruby', '~> 0.9.9'
Expand All @@ -45,7 +44,7 @@ def specification(version, default_adapter, platform = nil)
s.add_development_dependency 'rb-readline', '~> 0.5.1'
# updating minitest-reporters requires a new minitest which fails with gollum's tests.
s.add_development_dependency 'test-unit', '~> 3.3'
s.add_development_dependency 'minitest-reporters', '~> 1.4'
s.add_development_dependency 'minitest-reporters', '~> 1.5'
s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
s.add_development_dependency 'guard', '~> 2.16'
s.add_development_dependency 'guard-minitest', '~> 2.4'
Expand Down Expand Up @@ -93,7 +92,7 @@ def specification(version, default_adapter, platform = nil)
lib/gollum-lib/macro/global_toc.rb
lib/gollum-lib/macro/navigation.rb
lib/gollum-lib/macro/note.rb
lib/gollum-lib/macro/octicon.rb
lib/gollum-lib/macro/icon.rb
lib/gollum-lib/macro/series.rb
lib/gollum-lib/macro/video.rb
lib/gollum-lib/macro/warn.rb
Expand Down
6 changes: 2 additions & 4 deletions lib/gollum-lib/filter/macro.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ~*~ encoding: utf-8 ~*~
require 'octicons'


# Replace specified tokens with dynamically generated content.
class Gollum::Filter::Macro < Gollum::Filter
Expand Down Expand Up @@ -53,9 +53,7 @@ def process(data)
begin
Gollum::Macro.instance(macro, @markup.wiki, @markup.page).render(*args)
rescue StandardError => e
icon = Octicons::Octicon.new('zap', {width: 24, height: 24})
icon.options[:class] << ' mr-2'
"<div class='flash flash-error'>#{icon.to_svg}Macro Error for #{macro}: #{e.message}</div>"
%Q(<div class="flash flash-error gollum-macro-error my-2">Macro Error for #{macro}: #{e.message}</div>)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gollum-lib/macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(macro_name)
end

def render(*_args)
"!!!Unknown macro: #{@macro_name}!!!"
html_error("Unknown macro: #{@macro_name}")
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/gollum-lib/macro/flash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Gollum
class Macro
class Flash < Gollum::Macro
def render(message, icon='', type='')
flash_type = ['warn', 'error', 'success'].include?(type) ? "flash-#{type}" : ''
flash_icon = icon.empty? ? '' : %Q(data-gollum-icon="#{icon}")
%Q(<div class="flash #{flash_type} my-2" #{flash_icon}>#{message}</div>)
end
end
end
end
9 changes: 9 additions & 0 deletions lib/gollum-lib/macro/icon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Gollum
class Macro
class Icon < Gollum::Macro
def render(icon)
%Q(<div class="gollum-icon" data-gollum-icon="#{icon}"></div>)
end
end
end
end
14 changes: 2 additions & 12 deletions lib/gollum-lib/macro/note.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
module Gollum
class Macro
class Note < Gollum::Macro
def render(notice, octicon = 'info')
icon = ""
unless octicon.empty?
begin
icon = Octicons::Octicon.new(octicon, {width: 24, height: 24})
rescue RuntimeError
icon = Octicons::Octicon.new('info', {width: 24, height: 24})
end
icon.options[:class] << ' mr-2'
icon = icon.to_svg
end
"<div class='flash'>#{icon}#{notice}</div>"
def render(notice)
%Q(<div class="flash gollum-note my-2">#{notice}</div>)
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions lib/gollum-lib/macro/octicon.rb

This file was deleted.

4 changes: 1 addition & 3 deletions lib/gollum-lib/macro/warn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Gollum
class Macro
class Warn < Gollum::Macro
def render(warning)
icon = Octicons::Octicon.new('alert', {width: 24, height: 24})
icon.options[:class] << ' mr-2'
"<div class='flash flash-warn'>#{icon.to_svg}#{warning}</div>"
%Q(<div class="flash flash-warn gollum-warning my-2">#{warning}</div>)
end
end
end
Expand Down
23 changes: 13 additions & 10 deletions test/test_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,29 @@ def render(opts)
assert_match /<audio (.*) src="#{file}"(.*)> (.*)<\/audio>/, @wiki.pages[0].formatted_data
end

test "Octicon macro given a symbol and dimensions displays octicon" do
@wiki.write_page("OcticonMacroPage", :markdown, '<<Octicon("globe", 64, 64)>>', commit_details)
assert_match /<div><svg.*class=\"octicon octicon-globe\".*/, @wiki.pages[0].formatted_data
assert_match /<div><svg.*height=\"64\"/, @wiki.pages[0].formatted_data
assert_match /<div><svg.*width=\"64\"/, @wiki.pages[0].formatted_data
test "Icon macro given a symbol renders gollum-icon div with data-gollum-icon attribute" do
@wiki.write_page("IconMacroPage", :markdown, '<<Icon("globe")>>', commit_details)
assert_match /<div class=\"gollum-icon\".*data-gollum-icon=\"globe\".*/, @wiki.pages[0].formatted_data
end

test "Flash macro given a type and icon name renders gollum-flash with data-* attributes" do
@wiki.write_page("FlashMacroPage", :markdown, '<<Flash("Not all those who wander are lost", "bell", "success")>>', commit_details)
assert_match /<div class=\"flash flash-success my-2\".*data-gollum-icon=\"bell\".*/, @wiki.pages[0].formatted_data
end

test "Note macro given a string displays a regular flash message box" do
@wiki.write_page("NoteMacroPage", :markdown, '<<Note("Did you know Bilbo is a Hobbit?")>>', commit_details)
assert_match /<div class=\"flash\"><svg.*class=\"octicon octicon-info mr-2\".*Did you know Bilbo.*/, @wiki.pages[0].formatted_data
assert_match /<div class=\"flash gollum-note my-2\">.*Did you know Bilbo.*/, @wiki.pages[0].formatted_data
end

test "Warn macro given a string displays a flash-warning message box" do
@wiki.write_page("WarnMacroPage", :markdown, '<<Warn("Be careful not to mention hobbits in conversation too much.")>>', commit_details)
assert_match /<div class=\"flash flash-warn\"><svg.*class=\"octicon octicon-alert mr-2\".*Be careful.*/, @wiki.pages[0].formatted_data
assert_match /<div class=\"flash flash-warn gollum-warning my-2\">.*Be careful.*/, @wiki.pages[0].formatted_data
end

test "Macro errors are reported in place in a flash-error message box" do
@wiki.write_page("OcticonMacroPage", :markdown, '<<Octicon("foobar", 64, 64)>>', commit_details)
assert_match /<div class=\"flash flash-error\"><svg.*class=\"octicon octicon-zap mr-2\".*Macro Error for Octicon: Couldn't find octicon symbol for "foobar".*/, @wiki.pages[0].formatted_data
@wiki.write_page("IconMacroPage", :markdown, '<<Note("foobar", 64, 64)>>', commit_details)
assert_match /<div class=\"flash flash-error gollum-macro-error my-2\">Macro Error for Note: wrong number of arguments.*/, @wiki.pages[0].formatted_data
end

test "Macros escape HTML" do
Expand All @@ -214,7 +217,7 @@ def render(opts)

test "Note macro renders HTML code" do
@wiki.write_page("HTMLNoteMacroPage", :markdown, '<<Note("<span>test</span>")>>', commit_details)
assert_match /<div class=\"flash\"><svg.*class=\"octicon octicon-info mr-2\".*<span>test<\/span>.*/, @wiki.pages[0].formatted_data
assert_match /<div class=\"flash gollum-note my-2\".*<span>test<\/span>.*/, @wiki.pages[0].formatted_data
end

test "Series macro escapes page names" do
Expand Down

0 comments on commit 63dd863

Please sign in to comment.