{"action":"created","comment":{"url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/comments/49208724","id":49208724,"diff_hunk":"@@ -0,0 +1,69 @@\n+require 'spec_helper'\n+\n+describe PDFKit::HTMLPreprocessor do\n+  describe \"#process\" do\n+    let(:preprocessor) { PDFKit::HTMLPreprocessor }\n+    let(:root_url) { 'http://example.com/' }  # This mirrors Middleware#root_url's response\n+    let(:protocol) { 'http' }\n+\n+    it \"correctly parses host-relative url with single quotes\" do\n+      original_body = %{<html><head><link href='/stylesheets/application.css' media='screen' rel='stylesheet' type='text/css' /></head><body><img alt='test' src=\"/test.png\" /></body></html>}\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq(\"<html><head><link href='http://example.com/stylesheets/application.css' media='screen' rel='stylesheet' type='text/css' /></head><body><img alt='test' src=\\\"http://example.com/test.png\\\" /></body></html>\")\n+    end\n+\n+    it \"correctly parses host-relative url with double quotes\" do\n+      original_body = %{<link href=\"/stylesheets/application.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />}\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq(\"<link href=\\\"http://example.com/stylesheets/application.css\\\" media=\\\"screen\\\" rel=\\\"stylesheet\\\" type=\\\"text/css\\\" />\")\n+    end\n+\n+    it \"correctly parses protocol-relative url with single quotes\" do\n+      original_body = %{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>}\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq(\"<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>\")\n+    end\n+\n+    it \"correctly parses protocol-relative url with double quotes\" do\n+      original_body = %{<link href=\"//fonts.googleapis.com/css?family=Open+Sans:400,600\" rel='stylesheet' type='text/css'>}\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq(\"<link href=\\\"http://fonts.googleapis.com/css?family=Open+Sans:400,600\\\" rel='stylesheet' type='text/css'>\")\n+    end\n+\n+    it \"correctly parses multiple tags where first one is root url\" do\n+      original_body = %{<a href='/'><img src='/logo.jpg' ></a>}\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq \"<a href='http://example.com/'><img src='http://example.com/logo.jpg' ></a>\"\n+    end\n+\n+    it \"returns the body even if there are no valid substitutions found\" do\n+      original_body = \"NO MATCH\"\n+      body = preprocessor.process original_body, root_url, protocol\n+      expect(body).to eq(\"NO MATCH\")\n+    end\n+\n+    context 'when root_url is nil' do\n+      it \"returns the body safely, without interpolating\" do\n+        original_body = %{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='/'><img src='/logo.jpg'></a>}\n+        body = preprocessor.process original_body, nil, protocol\n+        expect(body).to eq(%{<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='/'><img src='/logo.jpg'></a>})\n+      end\n+    end\n+\n+    context 'when protocol is nil' do\n+      it \"returns the body safely, without interpolating\" do\n+        original_body = %{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='/'><img src='/logo.jpg'></a>}\n+        body = preprocessor.process original_body, root_url, nil\n+        expect(body).to eq(%{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='http://example.com/'><img src='http://example.com/logo.jpg'></a>})\n+      end\n+    end\n+\n+    context 'when root_url and protocol are both nil' do\n+      it \"returns the body safely, without interpolating\" do\n+        original_body = %{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='/'><img src='/logo.jpg'></a>}\n+        body = preprocessor.process original_body, nil, nil\n+        expect(body).to eq(%{<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'><a href='/'><img src='/logo.jpg'></a>})","path":"spec/html_preprocessor_spec.rb","position":65,"original_position":65,"commit_id":"4e21e56fe8eb5b1f6280fb62f526eaa586f61b5f","original_commit_id":"4e21e56fe8eb5b1f6280fb62f526eaa586f61b5f","user":{"login":"danbernier","id":13077,"avatar_url":"https://avatars.githubusercontent.com/u/13077?v=3","gravatar_id":"","url":"https://api.github.com/users/danbernier","html_url":"https://github.com/danbernier","followers_url":"https://api.github.com/users/danbernier/followers","following_url":"https://api.github.com/users/danbernier/following{/other_user}","gists_url":"https://api.github.com/users/danbernier/gists{/gist_id}","starred_url":"https://api.github.com/users/danbernier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danbernier/subscriptions","organizations_url":"https://api.github.com/users/danbernier/orgs","repos_url":"https://api.github.com/users/danbernier/repos","events_url":"https://api.github.com/users/danbernier/events{/privacy}","received_events_url":"https://api.github.com/users/danbernier/received_events","type":"User","site_admin":false},"body":"Ahhhh, I totally spaced out there. You're right. Hang on...","created_at":"2016-01-08T16:43:21Z","updated_at":"2016-01-08T16:43:21Z","html_url":"https://github.com/pdfkit/pdfkit/pull/344#discussion_r49208724","pull_request_url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344","_links":{"self":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/comments/49208724"},"html":{"href":"https://github.com/pdfkit/pdfkit/pull/344#discussion_r49208724"},"pull_request":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344"}}},"pull_request":{"url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344","id":55399116,"html_url":"https://github.com/pdfkit/pdfkit/pull/344","diff_url":"https://github.com/pdfkit/pdfkit/pull/344.diff","patch_url":"https://github.com/pdfkit/pdfkit/pull/344.patch","issue_url":"https://api.github.com/repos/pdfkit/pdfkit/issues/344","number":344,"state":"open","locked":false,"title":"Honor `root_url` in core","user":{"login":"danbernier","id":13077,"avatar_url":"https://avatars.githubusercontent.com/u/13077?v=3","gravatar_id":"","url":"https://api.github.com/users/danbernier","html_url":"https://github.com/danbernier","followers_url":"https://api.github.com/users/danbernier/followers","following_url":"https://api.github.com/users/danbernier/following{/other_user}","gists_url":"https://api.github.com/users/danbernier/gists{/gist_id}","starred_url":"https://api.github.com/users/danbernier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danbernier/subscriptions","organizations_url":"https://api.github.com/users/danbernier/orgs","repos_url":"https://api.github.com/users/danbernier/repos","events_url":"https://api.github.com/users/danbernier/events{/privacy}","received_events_url":"https://api.github.com/users/danbernier/received_events","type":"User","site_admin":false},"body":"@sigmavirus24 Here's a working solution for what I was proposing in #343.\r\n\r\nTo an end-user, the only effect is that the `:root_url` (and the `:protocol`) options now can be passed right to the PDFKit constructor. Configuring `root_url` still works, too.\r\n\r\nThis PR introduces `PDFKit::HtmlPreprocessor`, which could maybe also handle inserting the `<stylesheet>` tags, but I didn't want to change too much at once.\r\n\r\nWhat do you think?","created_at":"2016-01-07T22:23:16Z","updated_at":"2016-01-08T16:43:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b3ea364e9f645b36f003639c7d4e6dc7847354c6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344/commits","review_comments_url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344/comments","review_comment_url":"https://api.github.com/repos/pdfkit/pdfkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pdfkit/pdfkit/issues/344/comments","statuses_url":"https://api.github.com/repos/pdfkit/pdfkit/statuses/4e21e56fe8eb5b1f6280fb62f526eaa586f61b5f","head":{"label":"ContinuityControl:honor-root-url-in-core","ref":"honor-root-url-in-core","sha":"4e21e56fe8eb5b1f6280fb62f526eaa586f61b5f","user":{"login":"ContinuityControl","id":442713,"avatar_url":"https://avatars.githubusercontent.com/u/442713?v=3","gravatar_id":"","url":"https://api.github.com/users/ContinuityControl","html_url":"https://github.com/ContinuityControl","followers_url":"https://api.github.com/users/ContinuityControl/followers","following_url":"https://api.github.com/users/ContinuityControl/following{/other_user}","gists_url":"https://api.github.com/users/ContinuityControl/gists{/gist_id}","starred_url":"https://api.github.com/users/ContinuityControl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ContinuityControl/subscriptions","organizations_url":"https://api.github.com/users/ContinuityControl/orgs","repos_url":"https://api.github.com/users/ContinuityControl/repos","events_url":"https://api.github.com/users/ContinuityControl/events{/privacy}","received_events_url":"https://api.github.com/users/ContinuityControl/received_events","type":"Organization","site_admin":false},"repo":{"id":1860292,"name":"pdfkit","full_name":"ContinuityControl/pdfkit","owner":{"login":"ContinuityControl","id":442713,"avatar_url":"https://avatars.githubusercontent.com/u/442713?v=3","gravatar_id":"","url":"https://api.github.com/users/ContinuityControl","html_url":"https://github.com/ContinuityControl","followers_url":"https://api.github.com/users/ContinuityControl/followers","following_url":"https://api.github.com/users/ContinuityControl/following{/other_user}","gists_url":"https://api.github.com/users/ContinuityControl/gists{/gist_id}","starred_url":"https://api.github.com/users/ContinuityControl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ContinuityControl/subscriptions","organizations_url":"https://api.github.com/users/ContinuityControl/orgs","repos_url":"https://api.github.com/users/ContinuityControl/repos","events_url":"https://api.github.com/users/ContinuityControl/events{/privacy}","received_events_url":"https://api.github.com/users/ContinuityControl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ContinuityControl/pdfkit","description":"HTML+CSS to PDF using wkhtmltopdf","fork":true,"url":"https://api.github.com/repos/ContinuityControl/pdfkit","forks_url":"https://api.github.com/repos/ContinuityControl/pdfkit/forks","keys_url":"https://api.github.com/repos/ContinuityControl/pdfkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ContinuityControl/pdfkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ContinuityControl/pdfkit/teams","hooks_url":"https://api.github.com/repos/ContinuityControl/pdfkit/hooks","issue_events_url":"https://api.github.com/repos/ContinuityControl/pdfkit/issues/events{/number}","events_url":"https://api.github.com/repos/ContinuityControl/pdfkit/events","assignees_url":"https://api.github.com/repos/ContinuityControl/pdfkit/assignees{/user}","branches_url":"https://api.github.com/repos/ContinuityControl/pdfkit/branches{/branch}","tags_url":"https://api.github.com/repos/ContinuityControl/pdfkit/tags","blobs_url":"https://api.github.com/repos/ContinuityControl/pdfkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ContinuityControl/pdfkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ContinuityControl/pdfkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/ContinuityControl/pdfkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ContinuityControl/pdfkit/statuses/{sha}","languages_url":"https://api.github.com/repos/ContinuityControl/pdfkit/languages","stargazers_url":"https://api.github.com/repos/ContinuityControl/pdfkit/stargazers","contributors_url":"https://api.github.com/repos/ContinuityControl/pdfkit/contributors","subscribers_url":"https://api.github.com/repos/ContinuityControl/pdfkit/subscribers","subscription_url":"https://api.github.com/repos/ContinuityControl/pdfkit/subscription","commits_url":"https://api.github.com/repos/ContinuityControl/pdfkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/ContinuityControl/pdfkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/ContinuityControl/pdfkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/ContinuityControl/pdfkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/ContinuityControl/pdfkit/contents/{+path}","compare_url":"https://api.github.com/repos/ContinuityControl/pdfkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ContinuityControl/pdfkit/merges","archive_url":"https://api.github.com/repos/ContinuityControl/pdfkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ContinuityControl/pdfkit/downloads","issues_url":"https://api.github.com/repos/ContinuityControl/pdfkit/issues{/number}","pulls_url":"https://api.github.com/repos/ContinuityControl/pdfkit/pulls{/number}","milestones_url":"https://api.github.com/repos/ContinuityControl/pdfkit/milestones{/number}","notifications_url":"https://api.github.com/repos/ContinuityControl/pdfkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ContinuityControl/pdfkit/labels{/name}","releases_url":"https://api.github.com/repos/ContinuityControl/pdfkit/releases{/id}","created_at":"2011-06-07T14:45:41Z","updated_at":"2015-03-05T19:53:23Z","pushed_at":"2016-01-08T16:34:58Z","git_url":"git://github.com/ContinuityControl/pdfkit.git","ssh_url":"git@github.com:ContinuityControl/pdfkit.git","clone_url":"https://github.com/ContinuityControl/pdfkit.git","svn_url":"https://github.com/ContinuityControl/pdfkit","homepage":null,"size":16409,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"pdfkit:master","ref":"master","sha":"ad202a0944208bf09011fec95437e042c38ad0c5","user":{"login":"pdfkit","id":1521782,"avatar_url":"https://avatars.githubusercontent.com/u/1521782?v=3","gravatar_id":"","url":"https://api.github.com/users/pdfkit","html_url":"https://github.com/pdfkit","followers_url":"https://api.github.com/users/pdfkit/followers","following_url":"https://api.github.com/users/pdfkit/following{/other_user}","gists_url":"https://api.github.com/users/pdfkit/gists{/gist_id}","starred_url":"https://api.github.com/users/pdfkit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdfkit/subscriptions","organizations_url":"https://api.github.com/users/pdfkit/orgs","repos_url":"https://api.github.com/users/pdfkit/repos","events_url":"https://api.github.com/users/pdfkit/events{/privacy}","received_events_url":"https://api.github.com/users/pdfkit/received_events","type":"Organization","site_admin":false},"repo":{"id":678938,"name":"pdfkit","full_name":"pdfkit/pdfkit","owner":{"login":"pdfkit","id":1521782,"avatar_url":"https://avatars.githubusercontent.com/u/1521782?v=3","gravatar_id":"","url":"https://api.github.com/users/pdfkit","html_url":"https://github.com/pdfkit","followers_url":"https://api.github.com/users/pdfkit/followers","following_url":"https://api.github.com/users/pdfkit/following{/other_user}","gists_url":"https://api.github.com/users/pdfkit/gists{/gist_id}","starred_url":"https://api.github.com/users/pdfkit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdfkit/subscriptions","organizations_url":"https://api.github.com/users/pdfkit/orgs","repos_url":"https://api.github.com/users/pdfkit/repos","events_url":"https://api.github.com/users/pdfkit/events{/privacy}","received_events_url":"https://api.github.com/users/pdfkit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pdfkit/pdfkit","description":"A Ruby gem to transform HTML + CSS into PDFs using the command-line utility wkhtmltopdf","fork":false,"url":"https://api.github.com/repos/pdfkit/pdfkit","forks_url":"https://api.github.com/repos/pdfkit/pdfkit/forks","keys_url":"https://api.github.com/repos/pdfkit/pdfkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pdfkit/pdfkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pdfkit/pdfkit/teams","hooks_url":"https://api.github.com/repos/pdfkit/pdfkit/hooks","issue_events_url":"https://api.github.com/repos/pdfkit/pdfkit/issues/events{/number}","events_url":"https://api.github.com/repos/pdfkit/pdfkit/events","assignees_url":"https://api.github.com/repos/pdfkit/pdfkit/assignees{/user}","branches_url":"https://api.github.com/repos/pdfkit/pdfkit/branches{/branch}","tags_url":"https://api.github.com/repos/pdfkit/pdfkit/tags","blobs_url":"https://api.github.com/repos/pdfkit/pdfkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pdfkit/pdfkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pdfkit/pdfkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/pdfkit/pdfkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pdfkit/pdfkit/statuses/{sha}","languages_url":"https://api.github.com/repos/pdfkit/pdfkit/languages","stargazers_url":"https://api.github.com/repos/pdfkit/pdfkit/stargazers","contributors_url":"https://api.github.com/repos/pdfkit/pdfkit/contributors","subscribers_url":"https://api.github.com/repos/pdfkit/pdfkit/subscribers","subscription_url":"https://api.github.com/repos/pdfkit/pdfkit/subscription","commits_url":"https://api.github.com/repos/pdfkit/pdfkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/pdfkit/pdfkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/pdfkit/pdfkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/pdfkit/pdfkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/pdfkit/pdfkit/contents/{+path}","compare_url":"https://api.github.com/repos/pdfkit/pdfkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pdfkit/pdfkit/merges","archive_url":"https://api.github.com/repos/pdfkit/pdfkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pdfkit/pdfkit/downloads","issues_url":"https://api.github.com/repos/pdfkit/pdfkit/issues{/number}","pulls_url":"https://api.github.com/repos/pdfkit/pdfkit/pulls{/number}","milestones_url":"https://api.github.com/repos/pdfkit/pdfkit/milestones{/number}","notifications_url":"https://api.github.com/repos/pdfkit/pdfkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pdfkit/pdfkit/labels{/name}","releases_url":"https://api.github.com/repos/pdfkit/pdfkit/releases{/id}","created_at":"2010-05-21T13:21:26Z","updated_at":"2016-01-06T07:03:09Z","pushed_at":"2016-01-08T16:34:58Z","git_url":"git://github.com/pdfkit/pdfkit.git","ssh_url":"git@github.com:pdfkit/pdfkit.git","clone_url":"https://github.com/pdfkit/pdfkit.git","svn_url":"https://github.com/pdfkit/pdfkit","homepage":"","size":16774,"stargazers_count":2088,"watchers_count":2088,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":287,"mirror_url":null,"open_issues_count":18,"forks":287,"open_issues":18,"watchers":2088,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344"},"html":{"href":"https://github.com/pdfkit/pdfkit/pull/344"},"issue":{"href":"https://api.github.com/repos/pdfkit/pdfkit/issues/344"},"comments":{"href":"https://api.github.com/repos/pdfkit/pdfkit/issues/344/comments"},"review_comments":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344/comments"},"review_comment":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pdfkit/pdfkit/pulls/344/commits"},"statuses":{"href":"https://api.github.com/repos/pdfkit/pdfkit/statuses/4e21e56fe8eb5b1f6280fb62f526eaa586f61b5f"}}}}