Skip to content

Commit

Permalink
Remove sanitize_html_and_replace_env_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Sep 13, 2024
1 parent a23842c commit 992b00c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def self.run(params)

task_data = YAML.safe_load(yaml)

task_name = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(task_data["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(task_data["html_notes"])
task_name = Helper::DdgAppleAutomationHelper.sanitize_asana_html_notes(task_data["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_asana_html_notes(task_data["html_notes"])
end

begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ def self.sanitize_asana_html_notes(content)
.strip # remove leading and trailing whitespaces
.gsub(%r{<br\s*/?>}, "\n") # replace <br> tags with newlines
end

def self.sanitize_html_and_replace_env_vars(content)
content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } # replace environment variables
.gsub(/\s+/, ' ') # replace multiple whitespaces with a single space
.gsub(/>\s+</, '><') # remove spaces between HTML tags
.strip # remove leading and trailing whitespaces
.gsub(%r{<br\s*/?>}, "\n") # replace <br> tags with newlines
end
end
end
end
Expand Down
26 changes: 8 additions & 18 deletions spec/ddg_apple_automation_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,44 +71,34 @@ def load_file(file)
end
end

describe "#sanitize_html_and_replace_env_vars" do
it "substitutes all env variables" do
content = "<h2>${ASSIGNEE_ID} is publishing ${TAG} hotfix release</h2>"
ClimateControl.modify(
ASSIGNEE_ID: '12345',
TAG: 'v1.0.0'
) do
expect(sanitize_html_and_replace_env_vars(content)).to eq("<h2>12345 is publishing v1.0.0 hotfix release</h2>")
end
end

describe "#sanitize_asana_html_notes" do
it "removes newlines and leading/trailing spaces" do
content = " \nHello, \n\n World!\n This is a test. \n"
expect(sanitize_html_and_replace_env_vars(content)).to eq("Hello, World! This is a test.")
expect(sanitize_asana_html_notes(content)).to eq("Hello, World! This is a test.")
end

it "removes spaces between html tags" do
content = "<body> <h2>Hello, World! This is a test.</h2> </body>"
expect(sanitize_html_and_replace_env_vars(content)).to eq("<body><h2>Hello, World! This is a test.</h2></body>")
expect(sanitize_asana_html_notes(content)).to eq("<body><h2>Hello, World! This is a test.</h2></body>")
end

it "replaces multiple whitespaces with a single space" do
content = "<h2>Hello, World! This is a test.</h2>"
expect(sanitize_html_and_replace_env_vars(content)).to eq("<h2>Hello, World! This is a test.</h2>")
expect(sanitize_asana_html_notes(content)).to eq("<h2>Hello, World! This is a test.</h2>")
end

it "replaces <br> tags with new lines" do
content = "<h2>Hello, World!<br> This is a test.</h2>"
expect(sanitize_html_and_replace_env_vars(content)).to eq("<h2>Hello, World!\n This is a test.</h2>")
expect(sanitize_asana_html_notes(content)).to eq("<h2>Hello, World!\n This is a test.</h2>")
end

it "preserves HTML-escaped characters" do
content = "<body>Hello -&gt; World!</body>"
expect(sanitize_html_and_replace_env_vars(content)).to eq("<body>Hello -&gt; World!</body>")
expect(sanitize_asana_html_notes(content)).to eq("<body>Hello -&gt; World!</body>")
end

def sanitize_html_and_replace_env_vars(content)
Fastlane::Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(content)
def sanitize_asana_html_notes(content)
Fastlane::Helper::DdgAppleAutomationHelper.sanitize_asana_html_notes(content)
end
end
end

0 comments on commit 992b00c

Please sign in to comment.