shutterbug 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzU4MGE0MGI2N2VkZjE5N2U4MGFmMTAyN2FiNGQ1OWJjOGUxMDMxNA==
4
+ MmI4MzNiYzkwMWQzYmJlY2I2NmY2NmNjMWE0NmMwNjEzY2RjNzU2ZQ==
5
5
  data.tar.gz: !binary |-
6
- OGIxYzNmYjNhZDhjNDI2MmE2NWEwYmI2OWY2MTEzYjllNzAxZmEyYw==
6
+ YmNjNzEzYjkyNDViMDc1MzdmZmNiYTYwMWFhZTM1YmYwNzUxZTRmOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDc2YWQ3MmRiMmZlMzZiOTM2YmRlZmQ0ZWZlOTIzMzllMThmOGJmMDhmYzc5
10
- MzUwODYwNDIyMmRjYmMyMzU1OWE2ODJlZDRhZmZkMzk3YTQyNTRkZTA1NGRh
11
- ZTdjNGZjZGZkODE1YTkxMTc2MGEzMWE0MjgzOTM0NTE4YjhjYzk=
9
+ MTVhN2Q1MjhjYWNmYTQ3MDI2NGJkZjI4ZjM0NjAwNDBlM2RiZWU2OWM2ZDhh
10
+ OGIxZjlhNWZjZjFlMTVkZWJkNmY0MzliYWZkY2VmMTBhYTRjMGY0NDAyZGRl
11
+ NzhlZmVlZWJiMTRjOTRiYzA4ZjkyNGI0ZGQxNWMzYjk2NWE4NWE=
12
12
  data.tar.gz: !binary |-
13
- MGZhNzI1MTQxMjg5YWZjMWQ3MGNjODNjMzlkOGJjOGYwZWY3MGMyODBhZTc3
14
- YzYzNjMxNWZmNzcxMWUxMzFhYjU1MDAyYzE1YTMyYmIxNzE3YTBhNDkyOTZi
15
- ZWM3NGQ0MDA1YTRmOWJlMmM2ZTMwYjU4YTQ2ZjFjMmQ4OTZkZWU=
13
+ OGUzOWNiMTllMGRlODFmOTJlOTZjMDM4OWE5OTM1MGYzNjkzNWEzN2FiMmQz
14
+ OTgzYWRkNzhlMjBkYjFjY2I3MDkzYzU1YjAxZjZiZTYyNjA1NjIyZDQ0N2Y4
15
+ Yzg3NGE3YzMwNDQ3N2Y2MzE5NjJmNGRmY2ZiOTRjZmY1YWU2ZDg=
data/README.md CHANGED
@@ -91,6 +91,9 @@ And a Procfile which looks like this:
91
91
 
92
92
  ## Changes ##
93
93
 
94
+ * August 25, 2015 – v 0.5.5
95
+ * More aggressive single quote replacement in phantom_job.rb
96
+
94
97
  * August 14, 2015 – v 0.5.4
95
98
  * Fix single quote encoding issue in phantom_job.rb. DM:
96
99
  > Phantom's html entity decoder borks on single quotes when you have an
@@ -1,5 +1,5 @@
1
1
  module Shutterbug
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  autoload :Rackapp, "shutterbug/rackapp"
4
4
  autoload :Configuration, "shutterbug/configuration"
5
5
  autoload :Storage, "shutterbug/storage"
@@ -51,6 +51,8 @@
51
51
  var system = require('system'),
52
52
  fs = require('fs'),
53
53
  baseRegEx = /<\s*base[^>]+href\s*=\s*['"]([^'"]*)['"][^>]*>/i,
54
+ baseFixupRegEx = /(&((amp;)*)lt;\s*base\s+href\s*=\s*)(['"])([^'"]*)(['"])([^&]*&((amp;)*)gt;)/gi,
55
+ metaFixupRegEx = /(&((amp;)*)lt;\s*meta\s+content\s*=\s*)(['"])([^'"]*)(['"])(\s+http-equiv\s*=\s*)(['"])([^'"]*)(['"])([^&]*&(((amp;))*)gt;)/gi,
54
56
  viewportSize = { width: 1000, height: 700 },
55
57
  filename, output, quality, size, base, html;
56
58
 
@@ -71,10 +73,56 @@ if (system.args.length > 3) {
71
73
  // let 'er rip!
72
74
  renderPage();
73
75
 
76
+ // converts &quot; to &amp;quot; based on the number of already escaped amps found in the fixup regex
77
+ function escapeQuote(allAmps) {
78
+ var quote = "&quot;",
79
+ numEscapes = allAmps.split("amp").length - 1, // &('')lt; => 1 - 1 = 0 => &quot;, &(amp;)lt; => 2 - 1 = 1 => &amp;quot;, &(amp;amp;)lt; => 3 - 1 = 2 => &amp;amp;quot;
80
+ i;
81
+ for (i = 0; i < numEscapes; i++) {
82
+ quote = quote.replace('&', '&amp;');
83
+ }
84
+ return quote;
85
+ }
86
+
87
+ function fixupBase($0,$beforeQuote,$allAmps,$innerAmps,$leftQuote,$insideQuote,$rightQuote,$afterQuote) {
88
+ var escapedQuote = escapeQuote($allAmps);
89
+ return [$beforeQuote, escapedQuote, decodeURIComponent($insideQuote), escapedQuote, $afterQuote].join('');
90
+ }
91
+
92
+ function fixupMeta($0,$beforeQuotes,$allAmps,$innerAmps,$leftFirstQuote,$insideFirstQuote,$rightFirstQuote,$betweenQuotes,$leftSecondQuote,$insideSecondQuote,$rightSecondQuote,$afterQuotes) {
93
+ var escapedQuote = escapeQuote($allAmps);
94
+ return [$beforeQuotes, escapedQuote, decodeURIComponent($insideFirstQuote), escapedQuote, $betweenQuotes, escapedQuote, decodeURIComponent($insideSecondQuote), escapedQuote, $afterQuotes].join('');
95
+ }
96
+
97
+ function testFixup(regex, fixup, src, fixed) {
98
+ var result = src.replace(regex, fixup);
99
+ if (result !== fixed) {
100
+ console.log("Expected '" + fixed + "' got '" + result + "'")
101
+ }
102
+ }
103
+
74
104
  // Main function, called once
75
105
  function renderPage() {
106
+ var contents = fs.read(filename);
107
+
108
+ // change to true for testing
109
+ if (false) {
110
+ console.log("Testing base fixup...");
111
+ testFixup(baseFixupRegEx, fixupBase, "&lt;base href='http://concord-consortium.github.io/lara-interactive-api/'&gt;", "&lt;base href=&quot;http://concord-consortium.github.io/lara-interactive-api/&quot;&gt;");
112
+ testFixup(baseFixupRegEx, fixupBase, "&amp;lt;base href='http://concord-consortium.github.io/lara-interactive-api/'&amp;gt;", "&amp;lt;base href=&amp;quot;http://concord-consortium.github.io/lara-interactive-api/&amp;quot;&amp;gt;");
113
+ testFixup(baseFixupRegEx, fixupBase, "&amp;amp;lt;base href='http://concord-consortium.github.io/lara-interactive-api/'&amp;amp;gt;", "&amp;amp;lt;base href=&amp;amp;quot;http://concord-consortium.github.io/lara-interactive-api/&amp;amp;quot;&amp;amp;gt;");
114
+ console.log("Testing meta fixup...");
115
+ testFixup(metaFixupRegEx, fixupMeta, "&lt;meta content='text/html;charset=utf-8' http-equiv='Content-Type'&gt;", "&lt;meta content=&quot;text/html;charset=utf-8&quot; http-equiv=&quot;Content-Type&quot;&gt;");
116
+ testFixup(metaFixupRegEx, fixupMeta, "&amp;lt;meta content='text/html;charset=utf-8' http-equiv='Content-Type'&amp;gt;", "&amp;lt;meta content=&amp;quot;text/html;charset=utf-8&amp;quot; http-equiv=&amp;quot;Content-Type&amp;quot;&amp;gt;");
117
+ testFixup(metaFixupRegEx, fixupMeta, "&amp;amp;lt;meta content='text/html;charset=utf-8' http-equiv='Content-Type'&amp;amp;gt;", "&amp;amp;lt;meta content=&amp;amp;quot;text/html;charset=utf-8&amp;amp;quot; http-equiv=&amp;amp;quot;Content-Type&amp;amp;quot;&amp;amp;gt;");
118
+ }
119
+
120
+ // fixup old clients that send single quoted escaped attributes in the metadata
121
+ // the single quoted escaped text causes phantom to incorrectly parse the html
122
+ contents = contents.replace(baseFixupRegEx, fixupBase).replace(metaFixupRegEx, fixupMeta);
123
+
76
124
  // this is the initial load of the html provided by phantom_job.rb
77
- loadPage(fs.read(filename), function (page, base, hasChangedIframes) {
125
+ loadPage(contents, function (page, base, hasChangedIframes) {
78
126
  // At this point the page has been "walked", and if it includes iframes, loadPage() has been called on each iframe.
79
127
  // The iframe srces have been updated to a data-uri that has an image taken of the iframe contents.
80
128
  if (hasChangedIframes) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutterbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Paessel
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-14 00:00:00.000000000 Z
13
+ date: 2015-08-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler