diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 5d030232..00c3e3a1 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -3,6 +3,7 @@ require 'linguist/mime' require 'linguist/pathname' require 'escape_utils' +require 'yaml' module Linguist module BlobHelper @@ -65,6 +66,13 @@ module Linguist ['.xib', '.nib', '.pbxproj'].include?(pathname.extname) end + vendored_paths = YAML.load_file(File.expand_path("../vendor.yml", __FILE__)) + VendoredRegexp = Regexp.new(vendored_paths.join('|')) + + def vendored? + name =~ VendoredRegexp + end + # Determine if the blob contains bad content that can be used for various # cross site attacks. Right now this is limited to flash files -- the flash # plugin ignores the response content type and treats any URL as flash diff --git a/lib/linguist/vendor.yml b/lib/linguist/vendor.yml new file mode 100644 index 00000000..b32bb1f6 --- /dev/null +++ b/lib/linguist/vendor.yml @@ -0,0 +1,27 @@ +- yui +- tiny_mce +- ckeditor +- redbox +- active_scaffold +- rico_corner +- code_highlighter +- vendor +- bundle +- node_modules +- cache +- assets +- bookends +- dojo +- extjs +- sencha +- mochikit +- prototype(.*)\.js +- mootools\.js +- jquery([^.]*)(\.min)?\.js +- jquery\-\d\.\d\.\d(\.min)?\.js +- effects\.js +- controls\.js +- dragdrop\.js +- fabfile\.py +- less([^.]*)(\.min)?\.js +- less\-\d+\.\d+\.\d+(\.min)?\.js diff --git a/test/test_blob.rb b/test/test_blob.rb index 76129c0b..d8f7cc5a 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -114,6 +114,19 @@ class TestBlob < Test::Unit::TestCase assert blob("project.pbxproj").generated? end + def test_vendored + assert !blob("README").vendored? + + assert blob("node_modules/coffee-script/lib/coffee-script.js").vendored? + assert blob("vendor/plugins/will_paginate/lib/will_paginate.rb").vendored? + + assert blob("public/javascripts/jquery.js").vendored? + assert blob("public/javascripts/prototype.js").vendored? + assert blob("public/javascripts/effects.js").vendored? + assert blob("public/javascripts/controls.js").vendored? + assert blob("public/javascripts/dragdrop.js").vendored? + end + def test_language assert_equal Language['Ruby'], blob("foo.rb").language assert_equal Language['Ruby'], blob("script.rb").language