middleman-protect-emails 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84c68e8b63854b83c98d1bf221e0b241c6a63e4
|
4
|
+
data.tar.gz: 3d6f708efef61b1b8e6915cc391fa8c3aed4c862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a94eddb160e6990a5b39175278a8bef993d5f380f88af1123d134dd8d67f7e69581f3628778bcd25f56f82c5167c56548b98d9dbb3c7ec2f80d5e8bdc6d1e69
|
7
|
+
data.tar.gz: 0e6306db51b058b543373149ba7c4e1dbb0a49277d920479f02930ae26c45b946674271e99532f6cb90c59709eb6757b62ec1c9ae3a15f4b005e3ffba826eb24
|
data/README.md
CHANGED
@@ -28,7 +28,23 @@ Using this gem is as simple as adding the following line to your project's `conf
|
|
28
28
|
activate :protect_emails
|
29
29
|
```
|
30
30
|
|
31
|
-
And that's it! This will now protect all `mailto` links in your Middleman project.
|
31
|
+
And that's it! This will now protect all `mailto` links in your Middleman project.
|
32
|
+
|
33
|
+
### How it Works
|
34
|
+
|
35
|
+
If the middleware detects a `mailto` link on your page, it will automatically replace the link with an encrypted hash and insert a small script at the end of the page for the browser to decode it on page load. For example, if the following code was on one of your pages:
|
36
|
+
|
37
|
+
```html
|
38
|
+
<a href='mailto:hello@example.com'>Link</a>
|
39
|
+
```
|
40
|
+
|
41
|
+
It would automatically be replaced with:
|
42
|
+
|
43
|
+
```html
|
44
|
+
<a href='#email-protection-uryyb@rknzcyr.pbz'>Link</a>
|
45
|
+
```
|
46
|
+
|
47
|
+
This extension also encrypts link parameters (ex. `mailto:hello@example.com?subject=Some%20Subject`).
|
32
48
|
|
33
49
|
## Contributing
|
34
50
|
|
data/features/extension.feature
CHANGED
@@ -34,3 +34,13 @@ Feature: Email Protection
|
|
34
34
|
Given the Server is running at "test-app"
|
35
35
|
When I go to "/with_url_params.html"
|
36
36
|
Then I should see "<a href='#email-protection-rznvy@rknzcyr.pbz?fhowrpg=Grfg%20Fhowrpg&obql=Grfg%20Obql'></a>"
|
37
|
+
|
38
|
+
Scenario: Encrypts mailto link complex parameters
|
39
|
+
Given the Server is running at "test-app"
|
40
|
+
When I go to "/with_complex_url_params.html"
|
41
|
+
Then I should see "<a href='#email-protection-rznvy@ybpnyubfg'>localhost domain</a>"
|
42
|
+
Then I should see "<a href='#email-protection-rznvy@rknzcyr.pbz?fhowrpg=Fhowrpg+jvgu+cyhf+fvtaf'>plus sign in subject</a>"
|
43
|
+
Then I should see "<a href='#email-protection-rznvy@rknzcyr.pbz?fhowrpg=Fhowrpg%20jvgu%20fcnprf'>spaces in subject</a>"
|
44
|
+
Then I should see "<a href='#email-protection-rznvy@rknzcyr.pbz?fhowrpg=Grfg+Fhowrpg&pp=rznvy2@rknzcyr.pbz'>cc param</a>"
|
45
|
+
Then I should see "<a href='#email-protection-zl-p0z.cy3k_rznvy@rk-nzcyr.pb.hx?fhowrpg=Grfg+Fhowrpg&obql=Grfg%20Obql&pp=rznvy@rknzcyr.pbz'>crazy case</a>"
|
46
|
+
Then I should see "<a href='mailto:email'>@example.com hacker</a>"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<html>
|
2
|
+
<head></head>
|
3
|
+
<body>
|
4
|
+
<a href='mailto:email@localhost'>localhost domain</a>
|
5
|
+
<a href='mailto:email@example.com?subject=Subject+with+plus+signs'>plus sign in subject</a>
|
6
|
+
<a href='mailto:email@example.com?subject=Subject%20with%20spaces'>spaces in subject</a>
|
7
|
+
<a href='mailto:email@example.com?subject=Test+Subject&cc=email2@example.com'>cc param</a>
|
8
|
+
<a href='mailto:my-c0m.pl3x_email@ex-ample.co.uk?subject=Test+Subject&body=Test%20Body&cc=email@example.com'>crazy case</a>
|
9
|
+
<a href='mailto:email'>@example.com hacker</a>
|
10
|
+
</body>
|
11
|
+
</html>
|
@@ -41,7 +41,11 @@ class Middleman::ProtectEmailsExtension < ::Middleman::Extension
|
|
41
41
|
|
42
42
|
# Replaces mailto links with ROT13 equivalent
|
43
43
|
# TODO: Don't replace plaintext mailto links
|
44
|
-
|
44
|
+
invalid_character = '\s"\'>'
|
45
|
+
email_username = "[^@#{invalid_character}]+"
|
46
|
+
email_domain = "[^?#{invalid_character}]+"
|
47
|
+
email_param = "[^&#{invalid_character}]+"
|
48
|
+
new_content = body.gsub /mailto:(#{email_username}@#{email_domain}(\?#{email_param}(\&#{email_param})*)?)/is do
|
45
49
|
replaced_email = true
|
46
50
|
email = $1.tr 'A-Za-z','N-ZA-Mn-za-m'
|
47
51
|
"#email-protection-#{email}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-protect-emails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Sardesai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- fixtures/test-app/config.rb
|
57
57
|
- fixtures/test-app/source/index.html
|
58
58
|
- fixtures/test-app/source/with_body.html
|
59
|
+
- fixtures/test-app/source/with_complex_url_params.html
|
59
60
|
- fixtures/test-app/source/with_multiple_emails.html
|
60
61
|
- fixtures/test-app/source/with_no_email.html
|
61
62
|
- fixtures/test-app/source/with_url_params.html
|