From 6fd896e8f93b7b9dcc84710673e18092a999a255 Mon Sep 17 00:00:00 2001 From: datashaman Date: Thu, 24 Mar 2016 09:56:47 +0200 Subject: [PATCH 1/2] Use RFC3986 URL encoding and fix mailto: examples --- README.md | 6 +++--- src/views/default.blade.php | 2 +- src/views/email.blade.php | 2 +- src/views/whatsapp.blade.php | 2 +- tests/ShareTest.php | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 744508e..53b0706 100644 --- a/README.md +++ b/README.md @@ -98,15 +98,15 @@ Add Blade templating code in *share.mynewservice* view file to generate a URL fo Example: - https://mynewservice.example.com?url={{ urlencode($url) }}title={{ urlencode("Check this out! $title. See it here: $url") }} + https://mynewservice.example.com?url={{ rawurlencode($url) }}title={{ rawurlencode("Check this out! $title. See it here: $url") }} Another example for the *email* service. Change the service config to be *[ 'view' => 'whatever' ]* and put this in the view file: - mailto?subject={{ urlencode("Wow, check this: $title") }}body={{ urlencode("Check this out! $title. See it here: $url") }} + mailto:?subject={{ rawurlencode("Wow, check this: $title") }}body={{ rawurlencode("Check this out! $title. See it here: $url") }} Localizing? Easy, use Laravel's trans() call: - mailto:subject={{ urlencode(trans('share.email-subject', compact('url', 'title', 'media'))) }}body={{ urlencode(trans('share.email-body', compact('url', 'title', 'media'))) }} + mailto:?subject={{ rawurlencode(trans('share.email-subject', compact('url', 'title', 'media'))) }}body={{ rawurlencode(trans('share.email-body', compact('url', 'title', 'media'))) }} Create a file at resources/lang/en/share.php with your choice of subject and body. URLs arguably have a maximum length of 2000 characters. diff --git a/src/views/default.blade.php b/src/views/default.blade.php index 3b6c0f5..7f656a6 100644 --- a/src/views/default.blade.php +++ b/src/views/default.blade.php @@ -1 +1 @@ -{{ $service['uri'] }}?{{ isset($service['urlName']) ? $service['urlName'] : 'url' }}={{ urlencode($url) }}{{ isset($service['titleName']) ? $service['titleName'] : 'title' }}={{ urlencode($title) }}{{ $service['mediaName'] }}={{ urlencode($media) }} +{{ $service['uri'] }}?{{ isset($service['urlName']) ? $service['urlName'] : 'url' }}={{ rawurlencode($url) }}{{ isset($service['titleName']) ? $service['titleName'] : 'title' }}={{ rawurlencode($title) }}{{ $service['mediaName'] }}={{ rawurlencode($media) }} diff --git a/src/views/email.blade.php b/src/views/email.blade.php index 92abe01..40914f9 100644 --- a/src/views/email.blade.php +++ b/src/views/email.blade.php @@ -1 +1 @@ -mailto:?subject={{ urlencode($title) }}&body={{ urlencode($url) }} +mailto:?subject={{ rawurlencode($title) }}&body={{ rawurlencode($url) }} diff --git a/src/views/whatsapp.blade.php b/src/views/whatsapp.blade.php index bfb3453..7d408e1 100644 --- a/src/views/whatsapp.blade.php +++ b/src/views/whatsapp.blade.php @@ -1 +1 @@ -whatsapp://send?text={{ urlencode("$title $url") }} +whatsapp://send?text={{ rawurlencode("$title $url") }} diff --git a/tests/ShareTest.php b/tests/ShareTest.php index 9cd0590..76af7fb 100644 --- a/tests/ShareTest.php +++ b/tests/ShareTest.php @@ -21,11 +21,11 @@ class ShareTest extends TestCase "twitter" => "https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.example.com&text=Example", "viadeo" => "http://www.viadeo.com/?url=http%3A%2F%2Fwww.example.com&title=Example", "vk" => "http://vk.com/share.php?url=http%3A%2F%2Fwww.example.com&title=Example&image=Media&noparse=false", - "whatsapp" => "whatsapp://send?text=Example+http%3A%2F%2Fwww.example.com", - "whatsapp" => "whatsapp://send?text=Example+http%3A%2F%2Fwww.example.com", + "whatsapp" => "whatsapp://send?text=Example%20http%3A%2F%2Fwww.example.com", + "whatsapp" => "whatsapp://send?text=Example%20http%3A%2F%2Fwww.example.com", "service" => "http://service.example.com?url=http%3A%2F%2Fwww.example.com&title=Example&media=Media", - "service2" => "http://service2.example.com?url=http%3A%2F%2Fwww.example.com&title=Example&extra1=Extra+1&extra2=Extra+2", + "service2" => "http://service2.example.com?url=http%3A%2F%2Fwww.example.com&title=Example&extra1=Extra%201&extra2=Extra%202", ]; protected function getPackageProviders($app) @@ -112,7 +112,7 @@ public function testRenderUrlTitleAndMedia() public function testRenderExtra() { - $this->assertEquals('http://service2.example.com?url=http%3A%2F%2Fwww.example.com&extra1=Extra+1&extra2=Extra+2', + $this->assertEquals('http://service2.example.com?url=http%3A%2F%2Fwww.example.com&extra1=Extra%201&extra2=Extra%202', Share::load('http://www.example.com')->service2()); } @@ -321,7 +321,7 @@ public function testVk() */ public function testWhatsapp() { - $url = 'whatsapp://send?text=Example+http%3A%2F%2Fwww.example.com'; + $url = 'whatsapp://send?text=Example%20http%3A%2F%2Fwww.example.com'; $this->assertEquals($url, Share::load('http://www.example.com', 'Example')->whatsapp()); // $this->assertPageFound($url); } From 5cb49d55e21532c3753c7bf9d3fb83b368ec65b2 Mon Sep 17 00:00:00 2001 From: datashaman Date: Thu, 24 Mar 2016 10:05:27 +0200 Subject: [PATCH 2/2] Bump version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d5db648..ce8337c 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "laravel", "laravel5" ], - "version": "5.2.0", + "version": "5.2.1", "license": "MIT", "authors": [ {