{"action":"created","comment":{"url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/comments/48811710","id":48811710,"diff_hunk":"@@ -14,14 +14,78 @@\n \n (function(internal, testing) {\n \n-  var _numberValueRegex = /^\\s*[-+]?(\\d*\\.)?\\d+(e[-+]?\\d+)?\\s*$/;\n+  // Extra backslashes because otherwise JS interprets them incorrectly.\n+  var _numberValueRegexStr = '[-+]?(\\\\d*\\\\.)?\\\\d+(e[-+]?\\\\d+)?';\n \n   function isNumberValueString(cssString) {\n-    return _numberValueRegex.test(cssString);\n+    // Anchor the regex to the start and end of the string..\n+    var numberValueRegex = new RegExp('^\\\\s*' + _numberValueRegexStr + '\\\\s*$');\n+    return numberValueRegex.test(cssString);\n+  }\n+\n+  function isCalc(string) {\n+    return /^calc/.test(string); \n+  }\n+\n+  // Effectively returns a calc dictionary.\n+  function parseDimension(unitRegExp, string) {\n+    string = string.trim().toLowerCase();\n+\n+    // CSS allows lengths to be '0', so if px is a supported unit, return 0px.\n+    if (string == '0' && 'px'.search(unitRegExp) >= 0)\n+      return {px: 0};\n+\n+    // If we have parenthesis, we're a calc and need to start with 'calc'.\n+    if (!/^[^(]*$|^calc/.test(string)) {\n+      return;\n+    }\n+    string = string.replace(/^calc\\(/, '(');\n+\n+    // We tag units by prefixing them with 'U' (note that we are already\n+    // lowercase) to prevent problems with types which are substrings of\n+    // each other (although prefixes may be problematic!)\n+    var matchedUnits = {};\n+    string = string.replace(unitRegExp, function(match) {\n+      matchedUnits[match] = null;\n+      return 'U' + match;\n+    });\n+    var taggedUnitRegExp = 'U(' + unitRegExp.source + ')';\n+\n+    // Validating input is simply applying as many reductions as we can.\n+    var typeCheck = string.replace(new RegExp(_numberValueRegexStr, 'g'), 'N')\n+                          .replace(new RegExp('N' + taggedUnitRegExp, 'g'), 'D')\n+                          .replace(/\\s[+-]\\s/g, 'O')\n+                          .replace(/\\s/g, '');\n+    var reductions = [/N\\*(D)/g, /(N|D)[*/]N/g, /(N|D)O\\1/g, /\\((N|D)\\)/g];\n+    var i = 0;\n+    while (i < reductions.length) {\n+      if (reductions[i].test(typeCheck)) {\n+        typeCheck = typeCheck.replace(reductions[i], '$1');\n+        i = 0;\n+      } else {\n+        i++;\n+      }\n+    }\n+    if (typeCheck != 'D') {\n+      return;\n+    }\n+\n+    for (var unit in matchedUnits) {\n+      // TODO: Don't use eval here as it will throw up security flags.","path":"src/parsing.js","position":63,"original_position":63,"commit_id":"1e8fe376e05b7cc4175985ce3973fb0339166721","original_commit_id":"1e8fe376e05b7cc4175985ce3973fb0339166721","user":{"login":"rjwright","id":4714151,"avatar_url":"https://avatars.githubusercontent.com/u/4714151?v=3","gravatar_id":"","url":"https://api.github.com/users/rjwright","html_url":"https://github.com/rjwright","followers_url":"https://api.github.com/users/rjwright/followers","following_url":"https://api.github.com/users/rjwright/following{/other_user}","gists_url":"https://api.github.com/users/rjwright/gists{/gist_id}","starred_url":"https://api.github.com/users/rjwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjwright/subscriptions","organizations_url":"https://api.github.com/users/rjwright/orgs","repos_url":"https://api.github.com/users/rjwright/repos","events_url":"https://api.github.com/users/rjwright/events{/privacy}","received_events_url":"https://api.github.com/users/rjwright/received_events","type":"User","site_admin":false},"body":"Do we want to fix this before landing?","created_at":"2016-01-05T04:35:12Z","updated_at":"2016-01-05T04:35:12Z","html_url":"https://github.com/css-typed-om/typed-om/pull/57#discussion_r48811710","pull_request_url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/comments/48811710"},"html":{"href":"https://github.com/css-typed-om/typed-om/pull/57#discussion_r48811710"},"pull_request":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57","id":54319745,"html_url":"https://github.com/css-typed-om/typed-om/pull/57","diff_url":"https://github.com/css-typed-om/typed-om/pull/57.diff","patch_url":"https://github.com/css-typed-om/typed-om/pull/57.patch","issue_url":"https://api.github.com/repos/css-typed-om/typed-om/issues/57","number":57,"state":"open","locked":false,"title":"Add parsing for LengthValue","user":{"login":"wilddamon","id":1373458,"avatar_url":"https://avatars.githubusercontent.com/u/1373458?v=3","gravatar_id":"","url":"https://api.github.com/users/wilddamon","html_url":"https://github.com/wilddamon","followers_url":"https://api.github.com/users/wilddamon/followers","following_url":"https://api.github.com/users/wilddamon/following{/other_user}","gists_url":"https://api.github.com/users/wilddamon/gists{/gist_id}","starred_url":"https://api.github.com/users/wilddamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilddamon/subscriptions","organizations_url":"https://api.github.com/users/wilddamon/orgs","repos_url":"https://api.github.com/users/wilddamon/repos","events_url":"https://api.github.com/users/wilddamon/events{/privacy}","received_events_url":"https://api.github.com/users/wilddamon/received_events","type":"User","site_admin":false},"body":"Tests now included.","created_at":"2015-12-22T00:27:19Z","updated_at":"2016-01-05T04:35:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cabb28aed6378531e426fa2ce9ae434e9eed6844","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57/commits","review_comments_url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57/comments","review_comment_url":"https://api.github.com/repos/css-typed-om/typed-om/pulls/comments{/number}","comments_url":"https://api.github.com/repos/css-typed-om/typed-om/issues/57/comments","statuses_url":"https://api.github.com/repos/css-typed-om/typed-om/statuses/1e8fe376e05b7cc4175985ce3973fb0339166721","head":{"label":"wilddamon:parse","ref":"parse","sha":"1e8fe376e05b7cc4175985ce3973fb0339166721","user":{"login":"wilddamon","id":1373458,"avatar_url":"https://avatars.githubusercontent.com/u/1373458?v=3","gravatar_id":"","url":"https://api.github.com/users/wilddamon","html_url":"https://github.com/wilddamon","followers_url":"https://api.github.com/users/wilddamon/followers","following_url":"https://api.github.com/users/wilddamon/following{/other_user}","gists_url":"https://api.github.com/users/wilddamon/gists{/gist_id}","starred_url":"https://api.github.com/users/wilddamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilddamon/subscriptions","organizations_url":"https://api.github.com/users/wilddamon/orgs","repos_url":"https://api.github.com/users/wilddamon/repos","events_url":"https://api.github.com/users/wilddamon/events{/privacy}","received_events_url":"https://api.github.com/users/wilddamon/received_events","type":"User","site_admin":false},"repo":{"id":46467310,"name":"typed-om","full_name":"wilddamon/typed-om","owner":{"login":"wilddamon","id":1373458,"avatar_url":"https://avatars.githubusercontent.com/u/1373458?v=3","gravatar_id":"","url":"https://api.github.com/users/wilddamon","html_url":"https://github.com/wilddamon","followers_url":"https://api.github.com/users/wilddamon/followers","following_url":"https://api.github.com/users/wilddamon/following{/other_user}","gists_url":"https://api.github.com/users/wilddamon/gists{/gist_id}","starred_url":"https://api.github.com/users/wilddamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilddamon/subscriptions","organizations_url":"https://api.github.com/users/wilddamon/orgs","repos_url":"https://api.github.com/users/wilddamon/repos","events_url":"https://api.github.com/users/wilddamon/events{/privacy}","received_events_url":"https://api.github.com/users/wilddamon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wilddamon/typed-om","description":"Prototype for CSS Typed OM","fork":true,"url":"https://api.github.com/repos/wilddamon/typed-om","forks_url":"https://api.github.com/repos/wilddamon/typed-om/forks","keys_url":"https://api.github.com/repos/wilddamon/typed-om/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wilddamon/typed-om/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wilddamon/typed-om/teams","hooks_url":"https://api.github.com/repos/wilddamon/typed-om/hooks","issue_events_url":"https://api.github.com/repos/wilddamon/typed-om/issues/events{/number}","events_url":"https://api.github.com/repos/wilddamon/typed-om/events","assignees_url":"https://api.github.com/repos/wilddamon/typed-om/assignees{/user}","branches_url":"https://api.github.com/repos/wilddamon/typed-om/branches{/branch}","tags_url":"https://api.github.com/repos/wilddamon/typed-om/tags","blobs_url":"https://api.github.com/repos/wilddamon/typed-om/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wilddamon/typed-om/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wilddamon/typed-om/git/refs{/sha}","trees_url":"https://api.github.com/repos/wilddamon/typed-om/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wilddamon/typed-om/statuses/{sha}","languages_url":"https://api.github.com/repos/wilddamon/typed-om/languages","stargazers_url":"https://api.github.com/repos/wilddamon/typed-om/stargazers","contributors_url":"https://api.github.com/repos/wilddamon/typed-om/contributors","subscribers_url":"https://api.github.com/repos/wilddamon/typed-om/subscribers","subscription_url":"https://api.github.com/repos/wilddamon/typed-om/subscription","commits_url":"https://api.github.com/repos/wilddamon/typed-om/commits{/sha}","git_commits_url":"https://api.github.com/repos/wilddamon/typed-om/git/commits{/sha}","comments_url":"https://api.github.com/repos/wilddamon/typed-om/comments{/number}","issue_comment_url":"https://api.github.com/repos/wilddamon/typed-om/issues/comments{/number}","contents_url":"https://api.github.com/repos/wilddamon/typed-om/contents/{+path}","compare_url":"https://api.github.com/repos/wilddamon/typed-om/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wilddamon/typed-om/merges","archive_url":"https://api.github.com/repos/wilddamon/typed-om/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wilddamon/typed-om/downloads","issues_url":"https://api.github.com/repos/wilddamon/typed-om/issues{/number}","pulls_url":"https://api.github.com/repos/wilddamon/typed-om/pulls{/number}","milestones_url":"https://api.github.com/repos/wilddamon/typed-om/milestones{/number}","notifications_url":"https://api.github.com/repos/wilddamon/typed-om/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wilddamon/typed-om/labels{/name}","releases_url":"https://api.github.com/repos/wilddamon/typed-om/releases{/id}","created_at":"2015-11-19T04:21:38Z","updated_at":"2015-11-19T04:21:39Z","pushed_at":"2016-01-04T00:58:00Z","git_url":"git://github.com/wilddamon/typed-om.git","ssh_url":"git@github.com:wilddamon/typed-om.git","clone_url":"https://github.com/wilddamon/typed-om.git","svn_url":"https://github.com/wilddamon/typed-om","homepage":null,"size":248,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":0,"default_branch":"master"}},"base":{"label":"css-typed-om:master","ref":"master","sha":"cfe9642a24fe2b8a99bace7d7318c29fc9e25806","user":{"login":"css-typed-om","id":15916862,"avatar_url":"https://avatars.githubusercontent.com/u/15916862?v=3","gravatar_id":"","url":"https://api.github.com/users/css-typed-om","html_url":"https://github.com/css-typed-om","followers_url":"https://api.github.com/users/css-typed-om/followers","following_url":"https://api.github.com/users/css-typed-om/following{/other_user}","gists_url":"https://api.github.com/users/css-typed-om/gists{/gist_id}","starred_url":"https://api.github.com/users/css-typed-om/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/css-typed-om/subscriptions","organizations_url":"https://api.github.com/users/css-typed-om/orgs","repos_url":"https://api.github.com/users/css-typed-om/repos","events_url":"https://api.github.com/users/css-typed-om/events{/privacy}","received_events_url":"https://api.github.com/users/css-typed-om/received_events","type":"Organization","site_admin":false},"repo":{"id":46456802,"name":"typed-om","full_name":"css-typed-om/typed-om","owner":{"login":"css-typed-om","id":15916862,"avatar_url":"https://avatars.githubusercontent.com/u/15916862?v=3","gravatar_id":"","url":"https://api.github.com/users/css-typed-om","html_url":"https://github.com/css-typed-om","followers_url":"https://api.github.com/users/css-typed-om/followers","following_url":"https://api.github.com/users/css-typed-om/following{/other_user}","gists_url":"https://api.github.com/users/css-typed-om/gists{/gist_id}","starred_url":"https://api.github.com/users/css-typed-om/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/css-typed-om/subscriptions","organizations_url":"https://api.github.com/users/css-typed-om/orgs","repos_url":"https://api.github.com/users/css-typed-om/repos","events_url":"https://api.github.com/users/css-typed-om/events{/privacy}","received_events_url":"https://api.github.com/users/css-typed-om/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/css-typed-om/typed-om","description":"Prototype for CSS Typed OM","fork":false,"url":"https://api.github.com/repos/css-typed-om/typed-om","forks_url":"https://api.github.com/repos/css-typed-om/typed-om/forks","keys_url":"https://api.github.com/repos/css-typed-om/typed-om/keys{/key_id}","collaborators_url":"https://api.github.com/repos/css-typed-om/typed-om/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/css-typed-om/typed-om/teams","hooks_url":"https://api.github.com/repos/css-typed-om/typed-om/hooks","issue_events_url":"https://api.github.com/repos/css-typed-om/typed-om/issues/events{/number}","events_url":"https://api.github.com/repos/css-typed-om/typed-om/events","assignees_url":"https://api.github.com/repos/css-typed-om/typed-om/assignees{/user}","branches_url":"https://api.github.com/repos/css-typed-om/typed-om/branches{/branch}","tags_url":"https://api.github.com/repos/css-typed-om/typed-om/tags","blobs_url":"https://api.github.com/repos/css-typed-om/typed-om/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/css-typed-om/typed-om/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/css-typed-om/typed-om/git/refs{/sha}","trees_url":"https://api.github.com/repos/css-typed-om/typed-om/git/trees{/sha}","statuses_url":"https://api.github.com/repos/css-typed-om/typed-om/statuses/{sha}","languages_url":"https://api.github.com/repos/css-typed-om/typed-om/languages","stargazers_url":"https://api.github.com/repos/css-typed-om/typed-om/stargazers","contributors_url":"https://api.github.com/repos/css-typed-om/typed-om/contributors","subscribers_url":"https://api.github.com/repos/css-typed-om/typed-om/subscribers","subscription_url":"https://api.github.com/repos/css-typed-om/typed-om/subscription","commits_url":"https://api.github.com/repos/css-typed-om/typed-om/commits{/sha}","git_commits_url":"https://api.github.com/repos/css-typed-om/typed-om/git/commits{/sha}","comments_url":"https://api.github.com/repos/css-typed-om/typed-om/comments{/number}","issue_comment_url":"https://api.github.com/repos/css-typed-om/typed-om/issues/comments{/number}","contents_url":"https://api.github.com/repos/css-typed-om/typed-om/contents/{+path}","compare_url":"https://api.github.com/repos/css-typed-om/typed-om/compare/{base}...{head}","merges_url":"https://api.github.com/repos/css-typed-om/typed-om/merges","archive_url":"https://api.github.com/repos/css-typed-om/typed-om/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/css-typed-om/typed-om/downloads","issues_url":"https://api.github.com/repos/css-typed-om/typed-om/issues{/number}","pulls_url":"https://api.github.com/repos/css-typed-om/typed-om/pulls{/number}","milestones_url":"https://api.github.com/repos/css-typed-om/typed-om/milestones{/number}","notifications_url":"https://api.github.com/repos/css-typed-om/typed-om/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/css-typed-om/typed-om/labels{/name}","releases_url":"https://api.github.com/repos/css-typed-om/typed-om/releases{/id}","created_at":"2015-11-19T00:34:31Z","updated_at":"2015-12-16T03:41:31Z","pushed_at":"2016-01-04T05:55:38Z","git_url":"git://github.com/css-typed-om/typed-om.git","ssh_url":"git@github.com:css-typed-om/typed-om.git","clone_url":"https://github.com/css-typed-om/typed-om.git","svn_url":"https://github.com/css-typed-om/typed-om","homepage":null,"size":729,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":2,"forks":5,"open_issues":2,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57"},"html":{"href":"https://github.com/css-typed-om/typed-om/pull/57"},"issue":{"href":"https://api.github.com/repos/css-typed-om/typed-om/issues/57"},"comments":{"href":"https://api.github.com/repos/css-typed-om/typed-om/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/css-typed-om/typed-om/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/css-typed-om/typed-om/statuses/1e8fe376e05b7cc4175985ce3973fb0339166721"}}}}