Skip to content

Commit

Permalink
sanitize_and_replace_env_vars -> sanitize_html_and_replace_env_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Sep 12, 2024
1 parent e1f1e5c commit 017e0fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.run(params)
template_content = Helper::DdgAppleAutomationHelper.load_file(template_file)
return unless template_content

html_text = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content)
html_text = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content)
create_story(asana_access_token, task_id, html_text: html_text)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def self.run(params)
if template_name
template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_create_action_item/templates/#{template_name}.yml")
template_content = YAML.safe_load(Helper::DdgAppleAutomationHelper.load_file(template_file))
task_name = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_and_replace_env_vars(template_content["html_notes"])
task_name = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["name"])
html_notes = Helper::DdgAppleAutomationHelper.sanitize_html_and_replace_env_vars(template_content["html_notes"])
end

begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.load_file(file)
UI.user_error!("Error: The file '#{file}' does not exist.")
end

def self.sanitize_and_replace_env_vars(content)
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
Expand Down
16 changes: 8 additions & 8 deletions spec/ddg_apple_automation_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,39 @@ def load_file(file)
end
end

describe "#sanitize_and_replace_env_vars" do
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_and_replace_env_vars(content)).to eq("<h2>12345 is publishing v1.0.0 hotfix release</h2>")
expect(sanitize_html_and_replace_env_vars(content)).to eq("<h2>12345 is publishing v1.0.0 hotfix release</h2>")
end
end

it "removes newlines and leading/trailing spaces" do
content = " \nHello, \n\n World!\n This is a test. \n"
expect(sanitize_and_replace_env_vars(content)).to eq("Hello, World! This is a test.")
expect(sanitize_html_and_replace_env_vars(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_and_replace_env_vars(content)).to eq("<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>")
end

it "replaces multiple whitespaces with a single space" do
content = "<h2>Hello, World! This is a test.</h2>"
expect(sanitize_and_replace_env_vars(content)).to eq("<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>")
end

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

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

0 comments on commit 017e0fe

Please sign in to comment.