nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: Polymer/vulcanize
Pull request #146 (2015-03-31 00:59:50)

Add charset meta tag if needed


Patch:
diff --git a/lib/constants.js b/lib/constants.js
index da7fbf9..9fff354 100644
--- a/lib/constants.js
+++ b/lib/constants.js
@@ -12,6 +12,7 @@ var JS = 'script:not([type]), script[type="text/javascript"], script[type="appli
 var URL_ATTR = ['href', 'src', 'action', 'style'];
 
 module.exports = {
+  CHARSET_META: '<meta charset="UTF-8">',
   EOL: require('os').EOL,
   ELEMENTS: 'polymer-element:not([assetpath])',
   ELEMENTS_NOSCRIPT: 'polymer-element[noscript]',
diff --git a/lib/vulcan.js b/lib/vulcan.js
index 128861e..6bab83b 100644
--- a/lib/vulcan.js
+++ b/lib/vulcan.js
@@ -344,6 +344,10 @@ function handleMainDocument() {
     removeCommentsAndWhitespace($);
   }
 
+  var charsetMeta = searchAll($, 'meta[charset]');
+  if (charsetMeta.length === 0) {
+    $('head').append(constants.CHARSET_META);
+  }
   writeFileSync(options.output, $.html(), true);
 }
 


Test patch:
diff --git a/test/html/default.html b/test/html/default.html
index 68f1516..188d688 100644
--- a/test/html/default.html
+++ b/test/html/default.html
@@ -10,7 +10,6 @@
 -->
 <html lang="en">
 <head>
-  <meta charset="UTF-8">
   <link rel="import" href="imports/simple-import.html">
   <link rel="import" href="imports/simple-import.html">
   <link rel="import" href="http://example.com/foo/bar.html">
diff --git a/test/test.js b/test/test.js
index c9027fe..1d7e72d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -496,6 +496,7 @@ suite('Vulcan', function() {
       var $ = require('whacko').load(vulcanized);
       assert.equal(searchAll($, 'body > div[hidden]').length, 1, 'only one div[hidden]');
       assert.equal(searchAll($, 'head > link[rel="import"]:not([href^="http://"])').length, 0, 'all relative imports removed');
+      assert.equal(searchAll($, 'head > meta[charset="UTF-8"]').length, 1, 'charset meta tag added.');
       assert.equal(searchAll($, 'polymer-element').length, 1, 'imports were deduplicated');
       assert.equal(searchAll($, 'polymer-element').attr('noscript'), null, 'noscript removed');
       assert.equal(getTextContent(searchAll($, 'polymer-element > script')), 'Polymer(\'my-element\');', 'polymer script included');
@@ -578,7 +579,7 @@ suite('Vulcan', function() {
     test('whitespace', function(done) {
       process({inputSrc: '<div>\n  <div>\n    hi&nbsp;&nbsp;\n    </div>\n</div>  <textarea>\t\tSome text\n  \t</textarea>', output: outputPath, strip: true}, function(outputs) {
         var vulcanized = outputs[outputPath];
-        assert.equal(vulcanized, '<html><head></head><body><div> <div> hi&nbsp;&nbsp; </div> </div> <textarea>\t\tSome text\n  \t</textarea></body></html>');
+        assert.equal(vulcanized, '<html><head><meta charset="UTF-8"></head><body><div> <div> hi&nbsp;&nbsp; </div> </div> <textarea>\t\tSome text\n  \t</textarea></body></html>');
         done();
       });
     });
Repository: Polymer/vulcanize
Pull request #213 (2015-07-01 22:56:26)

Add inputUrl option for gulp and grunt usage


Patch:
diff --git a/lib/pathresolver.js b/lib/pathresolver.js
index ad5702a..082f21c 100644
--- a/lib/pathresolver.js
+++ b/lib/pathresolver.js
@@ -45,7 +45,7 @@ PathResolver.prototype = {
             relUrl = this.rewriteURL(importUrl, mainDocUrl, attrValue);
           } else {
             relUrl = this.rewriteRelPath(importUrl, mainDocUrl, attrValue);
-            if (attr === 'assetpath' && relUrl.slice(-1) != '/') {
+            if (attr === 'assetpath' && relUrl.slice(-1) !== '/') {
               relUrl += '/';
             }
           }
diff --git a/lib/vulcan.js b/lib/vulcan.js
index 0b47080..928821e 100644
--- a/lib/vulcan.js
+++ b/lib/vulcan.js
@@ -60,6 +60,7 @@ var Vulcan = function Vulcan(opts) {
   this.stripComments = opts.stripComments;
   this.enableCssInlining = opts.inlineCss;
   this.enableScriptInlining = opts.inlineScripts;
+  this.inputUrl = opts.inputUrl;
   if (!opts.loader) {
     this.loader = buildLoader(this.abspath, this.excludes);
   } else {
@@ -328,6 +329,9 @@ Vulcan.prototype = {
   },
 
   process: function process(target, cb) {
+    if (this.inputUrl) {
+      target = this.inputUrl;
+    }
     if (this.abspath) {
       target = pathPosix.resolve('/', target);
     }
diff --git a/package.json b/package.json
index 229f83b..63a7629 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
     "mocha": "^2.2.4"
   },
   "scripts": {
-    "test": "node_modules/.bin/jshint --verbose lib/*.js bin/* test/*.js && node_modules/.bin/mocha"
+    "test": "jshint --verbose lib bin/vulcanize test && mocha"
   },
   "author": "The Polymer Project Authors",
   "license": "BSD-3-Clause",


Test patch:
diff --git a/test/test.js b/test/test.js
index 9435dad..7040c8c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -447,7 +447,7 @@ suite('Vulcan', function() {
       preds.hasAttrValue('href', 'imports/simple-import.html')
     );
 
-    var excludes = [path.resolve("test/html/imports/simple-import.html")];
+    var excludes = ["test/html/imports/simple-import.html"];
 
     test('Excluded imports are not inlined', function(done) {
       var options = {
@@ -572,4 +572,35 @@ suite('Vulcan', function() {
       }, options);
     });
   });
+
+  suite('Input URL', function() {
+    var options = {
+      inputUrl: 'test/html/default.html'
+    };
+
+    test('inputURL is used instead of argument to process', function(done) {
+      process('flibflabfloom!', function(err, doc) {
+        if (err) {
+          return done(err);
+        }
+        assert(doc);
+        done();
+      }, options);
+    });
+
+    test('gulp-vulcanize invocation with abspath', function(done) {
+      var options = {
+        abspath: path.resolve('test/html'),
+        inputUrl: '/default.html'
+      };
+
+      process('C:\\Users\\VulcanizeTester\\vulcanize\\test\\html\\default.html', function(err, doc) {
+        if (err) {
+          return done(err);
+        }
+        assert(doc);
+        done();
+      }, options);
+    });
+  });
 });
Repository: Polymer/vulcanize
Pull request #246 (2015-09-22 20:40:43)

Adding support for link media queries
Adding support for inlining CSS link media queries 


Patch:
diff --git a/lib/vulcan.js b/lib/vulcan.js
index 27dcee8..b3306b4 100644
--- a/lib/vulcan.js
+++ b/lib/vulcan.js
@@ -241,6 +241,7 @@ Vulcan.prototype = {
     var cssPromises = css_links.map(function(link) {
       var tag = link;
       var src = dom5.getAttribute(tag, 'href');
+      var media = dom5.getAttribute(tag, 'media');
       var uri = url.resolve(href, src);
       // let the loader handle the requests
       if (this.isExcludedHref(src)) {
@@ -250,6 +251,9 @@ Vulcan.prototype = {
       return this.loader.request(uri).then(function(content) {
         if (content) {
           content = this.pathResolver.rewriteURL(uri, href, content);
+          if (media) {
+            content = '@media ' + media + ' {' + content + '}'; 
+          }
           var style = dom5.constructors.element('style');
           dom5.setTextContent(style, '\n' + content + '\n');
           dom5.replace(tag, style);


Test patch:
diff --git a/test/html/external-stylesheet.html b/test/html/external-stylesheet.html
index cd219b4..e3ec21e 100644
--- a/test/html/external-stylesheet.html
+++ b/test/html/external-stylesheet.html
@@ -9,3 +9,5 @@
 -->
 <!-- Roboto Font on Google Font CDN -->
 <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,500italic,700,700italic">
+
+<link rel="stylesheet" href="imports/regular-style.css" media="(min-width: 800px)">
diff --git a/test/test.js b/test/test.js
index 3a847ab..c03d1d7 100644
--- a/test/test.js
+++ b/test/test.js
@@ -657,7 +657,7 @@ suite('Vulcan', function() {
       process('test/html/inline-styles.html', callback, options);
     });
 
-    test('External Scripts and Stylesheets are not removed', function(done) {
+    test('External Scripts and Stylesheets are not removed and media queries are retained', function(done) {
       var matchers = require('../lib/matchers');
       var input = 'test/html/external-stylesheet.html';
       process(input, function(err, doc) {
@@ -666,6 +666,10 @@ suite('Vulcan', function() {
         }
         var link = dom5.query(doc, matchers.CSS_LINK);
         assert(link);
+        var styles = dom5.queryAll(doc, matchers.CSS);
+        assert.equal(styles.length, 1);
+        var content = dom5.getTextContent(styles[0]);
+        assert(content.search(new RegExp(/@media \(min-width: 800px\) /g)) > -1, 'media query retained');
         done();
       }, options);
     });
Repository: Polymer/vulcanize
Pull request #296 (2016-01-14 00:11:44)

Make sure stripExclude has higher precedence than exclude


Patch:
diff --git a/lib/vulcan.js b/lib/vulcan.js
index 9509d08..451e7b9 100644
--- a/lib/vulcan.js
+++ b/lib/vulcan.js
@@ -201,13 +201,13 @@ Vulcan.prototype = {
           this.removeImportAndNewline(importNodes[i]);
           continue;
         }
-        if (this.isExcludedImport(im)) {
-          continue;
-        }
         if (this.isStrippedImport(im)) {
           this.removeImportAndNewline(importNodes[i]);
           continue;
         }
+        if (this.isExcludedImport(im)) {
+          continue;
+        }
         var importDoc = this.flatten(im, bodyFragment, mainDocUrl);
         // rewrite urls
         this.pathResolver.resolvePaths(importDoc, im.href, tree.href);


Test patch:
diff --git a/test/test.js b/test/test.js
index 59ad0de..eb0e834 100644
--- a/test/test.js
+++ b/test/test.js
@@ -597,6 +597,24 @@ suite('Vulcan', function() {
       process(inputPath, callback, options);
     });
 
+    test('Strip Excludes has more precedence than Excludes', function(done) {
+      var options = {
+        excludes: excludes,
+        stripExcludes: excludes
+      };
+
+      var callback = function(err, doc) {
+        if (err) {
+          return done(err);
+        }
+        var imports = dom5.queryAll(doc, excluded);
+        assert.equal(imports.length, 0);
+        done();
+      };
+
+      process(inputPath, callback, options);
+    });
+
     test('Excluded comments are removed', function(done) {
       var options = {
         stripComments: true
Repository: Polymer/vulcanize
Pull request #298 (2016-01-16 02:57:43)

Prevent double slash in docBaseUrl.


Patch:
diff --git a/lib/pathresolver.js b/lib/pathresolver.js
index a34eb3a..9927248 100644
--- a/lib/pathresolver.js
+++ b/lib/pathresolver.js
@@ -112,6 +112,9 @@ PathResolver.prototype = {
       var baseTarget = dom5.getAttribute(base, 'target');
       dom5.remove(base);
       if (baseUrl) {
+        if (baseUrl.slice(-1) === '/') {
+          baseUrl = baseUrl.slice(0, -1);
+        }
         var docBaseUrl = url.resolve(docUrl, baseUrl + '/.index.html');
         this.resolvePaths(doc, docBaseUrl, docUrl);
       }


Test patch:
diff --git a/test/test.js b/test/test.js
index 581a77c..a4b6a64 100644
--- a/test/test.js
+++ b/test/test.js
@@ -198,6 +198,39 @@ suite('Path Resolver', function() {
     assert.equal(actual, expectedBase, 'base');
   });
 
+  test('Resolve Paths with <base> having a trailing /', function() {
+    var htmlBase = [
+      '<base href="zork/">',
+      '<link rel="import" href="../polymer/polymer.html">',
+      '<link rel="stylesheet" href="my-element.css">',
+      '<dom-module id="my-element">',
+      '<template>',
+      '<style>:host { background-image: url(background.svg); }</style>',
+      '</template>',
+      '</dom-module>',
+      '<script>Polymer({is: "my-element"})</script>'
+    ].join('\n');
+
+    var expectedBase = [
+      '<html><head>',
+      '<link rel="import" href="my-element/polymer/polymer.html">',
+      '<link rel="stylesheet" href="my-element/zork/my-element.css">',
+      '</head><body><dom-module id="my-element" assetpath="my-element/zork/">',
+      '<template>',
+      '<style>:host { background-image: url("my-element/zork/background.svg"); }</style>',
+      '</template>',
+      '</dom-module>',
+      '<script>Polymer({is: "my-element"})</script></body></html>'
+    ].join('\n');
+
+    var ast = parse(htmlBase);
+    pathresolver.acid(ast, inputPath);
+    pathresolver.resolvePaths(ast, inputPath, outputPath);
+
+    var actual = serialize(ast);
+    assert.equal(actual, expectedBase, 'base');
+  });
+
   test('Resolve <base target>', function() {
     var htmlBase = [
       '<base target="_blank">',
Repository: Polymer/vulcanize
Pull request #405 (2016-12-22 19:37:36)

Assetpath fix
Merges in the @josh-bradley branch that fixed asset paths for same-folder.  Thanks, Josh!  Updated CHANGELOG.md


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f8acb9..c88a72d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 
 ## Unreleased
 
+- Fix for how assetpath is set when in the same directory, where assetpath attribute
+  for components in same directly were incorrectly set to "/".
+
 ## 1.15.1 - 2016-12-16
 - Amended README and minor text fixes to CHANGELOG post release.
 
diff --git a/lib/pathresolver.js b/lib/pathresolver.js
index 9927248..724ee3c 100644
--- a/lib/pathresolver.js
+++ b/lib/pathresolver.js
@@ -45,7 +45,7 @@ PathResolver.prototype = {
             relUrl = this.rewriteURL(importUrl, mainDocUrl, attrValue);
           } else {
             relUrl = this.rewriteRelPath(importUrl, mainDocUrl, attrValue);
-            if (attr === 'assetpath' && relUrl.slice(-1) !== '/') {
+            if (attr === 'assetpath' && relUrl.length > 0 && relUrl.slice(-1) !== '/') {
               relUrl += '/';
             }
           }


Test patch:
diff --git a/test/test.js b/test/test.js
index 0519484..14df26d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -265,6 +265,29 @@ suite('Path Resolver', function() {
     assert.equal(actual, base, 'templated urls');
   });
 
+  test('Rewrite assetpath in same directory', function() {
+    var html = [
+      '<dom-module id="my-element" assetpath="./">',
+      '<template>',
+      '</template>',
+      '</dom-module>',
+      '<script>Polymer({is: "my-element"})</script>'
+    ].join('\n');
+
+    var expected = [
+      '<html><head></head><body><dom-module id="my-element" assetpath="">',
+      '<template>',
+      '</template>',
+      '</dom-module>',
+      '<script>Polymer({is: "my-element"})</script></body></html>'
+    ].join('\n');
+
+    var ast = parse(html);
+    pathresolver.resolvePaths(ast, inputPath, inputPath);
+
+    var actual = serialize(ast);
+    assert.equal(actual, expected, 'relative');
+  });
 });
 
 suite('Vulcan', function() {