Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Use ERB::Util instead of CGI.escape to escape whatsapp strings to get…
Browse files Browse the repository at this point in the history
… the right encoding, use the whatsapp api url
  • Loading branch information
Tuuleh committed Jun 12, 2018
1 parent aa3d58b commit d413dc3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/liquid/shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_all(page)
variant = select_share_variant(button.sp_type, page)
view_params[:variant_id] = variant.id
# Prepend the desired query parameters (uri encoded) into the url we want to share
url = button.url << CGI.escape("?src=whatsapp&variant_id=#{variant.id}")
url = button.url << ERB::Util.url_encode("?src=whatsapp&variant_id=#{variant.id}")
view_params[:link_html] = button.sp_button_html.gsub('%7BLINK%7D', url)
end
shares[button.sp_type] = view_params
Expand Down
3 changes: 2 additions & 1 deletion app/services/share_variant_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def update_button
case @variant_type
when :whatsapp
@button.update(
sp_button_html: "<a class=\"whatsapp_large\" href=\"whatsapp://send?text=#{CGI.escape(@variant.text)}\"></a>",
sp_button_html: '<a class="whatsapp_large" href="https://api.whatsapp.com'\
"/send?text=#{ERB::Util.url_encode(@variant.text)}\"></a>",
url: @url
)
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20180507153911_create_share_whatsapps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def change
t.references :page, index: true, foreign_key: true
t.string :text
t.integer :button_id
t.integer :click_count, default: 0
t.integer :conversion_count, default: 0
t.integer :click_count, default: 0, null: false
t.integer :conversion_count, default: 0, null: false

t.timestamps null: false
end
Expand Down
15 changes: 5 additions & 10 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
t.text "body"
t.string "resource_id", null: false
t.string "resource_type", null: false
t.integer "author_id"
t.string "author_type"
t.integer "author_id"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
Expand All @@ -64,20 +64,13 @@
t.datetime "updated_at", null: false
end

create_table "authentication_nonces", force: :cascade do |t|
t.string "nonce"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["nonce"], name: "index_authentication_nonces_on_nonce"
end

create_table "calls", id: :serial, force: :cascade do |t|
t.integer "page_id"
t.integer "member_id"
t.string "member_phone_number"
t.datetime "created_at"
t.datetime "updated_at"
t.jsonb "target_call_info", default: {}, null: false
t.jsonb "target_call_info", default: "{}", null: false
t.json "member_call_events", default: [], array: true
t.integer "twilio_error_code"
t.json "target"
Expand Down Expand Up @@ -122,8 +115,8 @@
t.datetime "updated_at", null: false
t.boolean "visible", default: false
t.boolean "master", default: false
t.integer "formable_id"
t.string "formable_type"
t.integer "formable_id"
t.integer "position", default: 0, null: false
t.index ["formable_type", "formable_id"], name: "index_forms_on_formable_type_and_formable_id"
end
Expand Down Expand Up @@ -618,6 +611,8 @@
t.bigint "page_id"
t.string "text"
t.integer "button_id"
t.integer "click_count", default: 0, null: false
t.integer "conversion_count", default: 0, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["page_id"], name: "index_share_whatsapps_on_page_id"
Expand Down

0 comments on commit d413dc3

Please sign in to comment.