source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/authenticity_token.rb
Ruby
mit
12,419
main
8,191
# frozen_string_literal: true require 'rack/protection' require 'securerandom' require 'openssl' require 'base64' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery # # This mi...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/frame_options.rb
Ruby
mit
12,419
main
1,280
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Clickjacking # Supported browsers:: Internet Explorer 8, Firefox 3.6.9, Opera 10.50, # Safari 4.0, Chrome 4.1.249.1042 and later # More infos:: https://dev...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/remote_token.rb
Ruby
mit
12,419
main
625
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery # # Only accepts unsafe HTTP requests if a given access token matches...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/content_security_policy.rb
Ruby
mit
12,419
main
3,391
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: XSS and others # Supported browsers:: Firefox 23+, Safari 7+, Chrome 25+, Opera 15+ # # Description:: Content Security Policy, a mechanism web applications # can use ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/remote_referrer.rb
Ruby
mit
12,419
main
529
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery # # Does not accept unsafe HTTP requests if the Referer [sic] header ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/json_csrf.rb
Ruby
mit
12,419
main
1,824
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: all # More infos:: http://flask.pocoo.org/docs/0.10/security/#json-security # http://haacked.com/archive/2008/11/20/anatomy-of-...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/host_authorization.rb
Ruby
mit
12,419
main
3,392
# frozen_string_literal: true require 'rack/protection' require 'ipaddr' module Rack module Protection ## # Prevented attack:: DNS rebinding and other Host header attacks # Supported browsers:: all # More infos:: https://en.wikipedia.org/wiki/DNS_rebinding # https:...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/strict_transport.rb
Ruby
mit
12,419
main
1,502
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Protects against against protocol downgrade attacks and cookie hijacking. # Supported browsers:: all # More infos:: https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/referrer_policy.rb
Ruby
mit
12,419
main
834
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Secret leakage, third party tracking # Supported browsers:: mixed support # More infos:: https://www.w3.org/TR/referrer-policy/ # https://caniuse.com/#sear...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/ip_spoofing.rb
Ruby
mit
12,419
main
743
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: IP spoofing # Supported browsers:: all # More infos:: http://blog.c22.cc/2011/04/22/surveymonkey-ip-spoofing/ # # Detect (some) IP spoofing attacks. class IPSpoofing < ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/xss_header.rb
Ruby
mit
12,419
main
895
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Non-permanent XSS # Supported browsers:: Internet Explorer 8+ and Chrome # More infos:: http://blogs.msdn.com/b/ie/archive/2008/07/01/ie8-security-part-iv-the-xss-filter.aspx #...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/path_traversal.rb
Ruby
mit
12,419
main
1,283
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Directory traversal # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Directory_traversal # # Unescapes '/' and '.', expands +path_info+. # Thus <t...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/cookie_tossing.rb
Ruby
mit
12,419
main
2,170
# frozen_string_literal: true require 'rack/protection' require 'pathname' module Rack module Protection ## # Prevented attack:: Cookie Tossing # Supported browsers:: all # More infos:: https://github.com/blog/1466-yummy-cookies-across-domains # # Does not accept HTTP requests if t...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/http_origin.rb
Ruby
mit
12,419
main
1,521
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: Google Chrome 2, Safari 4 and later # More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery # http://tools.ietf....
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/base.rb
Ruby
mit
12,419
main
3,790
# frozen_string_literal: true require 'rack/protection' require 'rack/utils' require 'digest' require 'logger' require 'uri' module Rack module Protection class Base DEFAULT_OPTIONS = { reaction: :default_reaction, logging: true, message: 'Forbidden', encryptor: Digest::SHA1, sessi...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/session_hijacking.rb
Ruby
mit
12,419
main
1,127
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: Session Hijacking # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Session_hijacking # # Tracks request properties like the user agent in the session ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/escaped_params.rb
Ruby
mit
12,419
main
2,361
# frozen_string_literal: true require 'rack/protection' require 'rack/utils' require 'tempfile' begin require 'escape_utils' rescue LoadError end module Rack module Protection ## # Prevented attack:: XSS # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Cross-site_s...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection/form_token.rb
Ruby
mit
12,419
main
758
# frozen_string_literal: true require 'rack/protection' module Rack module Protection ## # Prevented attack:: CSRF # Supported browsers:: all # More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery # # Only accepts submitted forms if a given access token matches the ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/spec_helper.rb
Ruby
mit
12,419
main
3,773
# frozen_string_literal: true require 'rack/protection' require 'rack/test' require 'rack' Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f } # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_P...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/support/not_implemented_as_pending.rb
Ruby
mit
12,419
main
635
# frozen_string_literal: true # see http://blog.101ideas.cz/posts/pending-examples-via-not-implemented-error-in-rspec.html module NotImplementedAsPending def self.included(base) base.class_eval do alias_method :__finish__, :finish remove_method :finish end end def finish(reporter) if @ex...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/support/spec_helpers.rb
Ruby
mit
12,419
main
880
# frozen_string_literal: true require 'forwardable' module SpecHelpers extend Forwardable def_delegators :last_response, :body, :headers, :status, :errors def_delegators :current_session, :env_for attr_writer :app def app @app ||= nil @app || mock_app(DummyApp) end def mock_app(app = nil, lint...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/support/dummy_app.rb
Ruby
mit
12,419
main
241
# frozen_string_literal: true module DummyApp def self.call(env) Thread.current[:last_env] = env body = (env['REQUEST_METHOD'] == 'HEAD' ? '' : 'ok') [200, { 'content-type' => env['wants'] || 'text/plain' }, [body]] end end
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/support/shared_examples.rb
Ruby
mit
12,419
main
1,502
# frozen_string_literal: true RSpec.shared_examples_for 'any rack application' do it 'should not interfere with normal get requests' do expect(get('/')).to be_ok expect(body).to eq('ok') end it 'should not interfere with normal head requests' do expect(head('/')).to be_ok end it 'should not lea...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/remote_token_spec.rb
Ruby
mit
12,419
main
2,667
# frozen_string_literal: true RSpec.describe Rack::Protection::RemoteToken do let(:token) { described_class.random_token } let(:masked_token) { described_class.token(session) } let(:bad_token) { Base64.strict_encode64('badtoken') } let(:session) { { csrf: token } } it_behaves_like 'any rack application' ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/host_authorization_spec.rb
Ruby
mit
12,419
main
13,703
# frozen_string_literal: true require 'stringio' RSpec.describe Rack::Protection::HostAuthorization do it_behaves_like 'any rack application' def assert_response(outcome:, headers:, last_response:) fail_message = "Expected outcome '#{outcome}' for headers '#{headers}' " \ "last_response.st...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/session_hijacking_spec.rb
Ruby
mit
12,419
main
1,258
# frozen_string_literal: true RSpec.describe Rack::Protection::SessionHijacking do it_behaves_like 'any rack application' it 'accepts a session without changes to tracked parameters' do session = { foo: :bar } get '/', {}, 'rack.session' => session get '/', {}, 'rack.session' => session expect(ses...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/frame_options_spec.rb
Ruby
mit
12,419
main
1,289
# frozen_string_literal: true RSpec.describe Rack::Protection::FrameOptions do it_behaves_like 'any rack application' it 'should set the X-Frame-Options' do expect(get('/', {}, 'wants' => 'text/html').headers['X-Frame-Options']).to eq('SAMEORIGIN') end it 'should not set the X-Frame-Options for other con...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/protection_spec.rb
Ruby
mit
12,419
main
5,279
# frozen_string_literal: true require 'stringio' RSpec.describe Rack::Protection do it_behaves_like 'any rack application' it 'passes on options' do mock_app do # the :track option is used by session_hijacking use Rack::Protection, track: ['HTTP_FOO'], use: [:session_hijacking], except: [:remote_...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/remote_referrer_spec.rb
Ruby
mit
12,419
main
980
# frozen_string_literal: true RSpec.describe Rack::Protection::RemoteReferrer do it_behaves_like 'any rack application' it 'accepts post requests with no referrer' do expect(post('/')).to be_ok end it 'does not accept post requests with no referrer if allow_empty_referrer is false' do mock_app do ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/escaped_params_spec.rb
Ruby
mit
12,419
main
1,837
# frozen_string_literal: true RSpec.describe Rack::Protection::EscapedParams do it_behaves_like 'any rack application' context 'escaping' do it 'escapes html entities' do mock_app do |env| request = Rack::Request.new(env) [200, { 'content-type' => 'text/plain' }, [request.params['foo']]]...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/json_csrf_spec.rb
Ruby
mit
12,419
main
2,978
# frozen_string_literal: true RSpec.describe Rack::Protection::JsonCsrf do it_behaves_like 'any rack application' module DummyAppWithBody module Closeable def close @closed = true end def closed? @closed end end def self.body @body ||= begin body...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/base_spec.rb
Ruby
mit
12,419
main
1,304
# frozen_string_literal: true RSpec.describe Rack::Protection::Base do subject { described_class.new(-> {}) } describe '#random_string' do it 'outputs a string of 32 characters' do expect(subject.random_string.length).to eq(32) end end describe '#referrer' do it 'Reads referrer from Referer...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/cookie_tossing_spec.rb
Ruby
mit
12,419
main
3,055
# frozen_string_literal: true RSpec.describe Rack::Protection::CookieTossing do it_behaves_like 'any rack application' context 'with default reaction' do before(:each) do mock_app do use Rack::Protection::CookieTossing run DummyApp end end it 'accepts requests with a singl...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/authenticity_token_spec.rb
Ruby
mit
12,419
main
3,806
# frozen_string_literal: true RSpec.describe Rack::Protection::AuthenticityToken do let(:token) { described_class.random_token } let(:masked_token) { described_class.token(session) } let(:bad_token) { Base64.strict_encode64('badtoken') } let(:session) { { csrf: token } } it_behaves_like 'any rack applicatio...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/strict_transport_spec.rb
Ruby
mit
12,419
main
1,516
# frozen_string_literal: true RSpec.describe Rack::Protection::StrictTransport do it_behaves_like 'any rack application' it 'should set the Strict-Transport-Security header' do expect(get('/', {}, 'wants' => 'text/html').headers['Strict-Transport-Security']).to eq('max-age=31536000') end it 'should allow...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/content_security_policy_spec.rb
Ruby
mit
12,419
main
3,231
# frozen_string_literal: true RSpec.describe Rack::Protection::ContentSecurityPolicy do it_behaves_like 'any rack application' it 'should set the Content Security Policy' do expect( get('/', {}, 'wants' => 'text/html').headers['Content-Security-Policy'] ).to eq("default-src 'self'") end it 'sho...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/http_origin_spec.rb
Ruby
mit
12,419
main
1,481
# frozen_string_literal: true RSpec.describe Rack::Protection::HttpOrigin do it_behaves_like 'any rack application' before(:each) do mock_app do use Rack::Protection::HttpOrigin run DummyApp end end %w[GET HEAD POST PUT DELETE].each do |method| it "accepts #{method} requests with no O...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/path_traversal_spec.rb
Ruby
mit
12,419
main
1,324
# frozen_string_literal: true RSpec.describe Rack::Protection::PathTraversal do it_behaves_like 'any rack application' context 'escaping' do before do mock_app { |e| [200, { 'content-type' => 'text/plain' }, [e['PATH_INFO']]] } end %w[/foo/bar /foo/bar/ / /.f /a.x].each do |path| it("does...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/form_token_spec.rb
Ruby
mit
12,419
main
1,698
# frozen_string_literal: true RSpec.describe Rack::Protection::FormToken do let(:token) { described_class.random_token } let(:masked_token) { described_class.token(session) } let(:bad_token) { Base64.strict_encode64('badtoken') } let(:session) { { csrf: token } } it_behaves_like 'any rack application' it...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/ip_spoofing_spec.rb
Ruby
mit
12,419
main
1,260
# frozen_string_literal: true RSpec.describe Rack::Protection::IPSpoofing do it_behaves_like 'any rack application' it 'accepts requests without X-Forward-For header' do get('/', {}, 'HTTP_CLIENT_IP' => '1.2.3.4', 'HTTP_X_REAL_IP' => '4.3.2.1') expect(last_response).to be_ok end it 'accepts requests ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/spec/lib/rack/protection/xss_header_spec.rb
Ruby
mit
12,419
main
1,955
# frozen_string_literal: true RSpec.describe Rack::Protection::XSSHeader do it_behaves_like 'any rack application' it 'should set the X-XSS-Protection' do expect(get('/', {}, 'wants' => 'text/html;charset=utf-8').headers['X-XSS-Protection']).to eq('1; mode=block') end it 'should set the X-XSS-Protection ...
github
Shopify/liquid
https://github.com/Shopify/liquid
Gemfile
Ruby
mit
11,774
main
732
# frozen_string_literal: true source 'https://rubygems.org' git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end gemspec gem "base64" group :benchmark, :test do gem 'benchmark-ips' gem 'memory_profiler' gem 'terminal-table' gem "lru_redux" install_if -> { RUBY_PLATFORM !~ /mingw...
github
Shopify/liquid
https://github.com/Shopify/liquid
Rakefile
Ruby
mit
11,774
main
3,774
# frozen_string_literal: true require 'rake' require 'rake/testtask' $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__)) require "liquid/version" task(default: [:test, :rubocop]) desc('run test suite with default parser') Rake::TestTask.new(:base_test) do |t| t.libs << 'lib' << 'test' t.test_files = FileLis...
github
Shopify/liquid
https://github.com/Shopify/liquid
liquid.gemspec
Ruby
mit
11,774
main
1,100
# encoding: utf-8 # frozen_string_literal: true lib = File.expand_path('../lib/', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "liquid/version" Gem::Specification.new do |s| s.name = "liquid" s.version = Liquid::VERSION s.platform = Gem::Platform::RUBY s.summary ...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/memory_profile.rb
Ruby
mit
11,774
main
1,606
# frozen_string_literal: true require 'benchmark/ips' require 'memory_profiler' require 'terminal-table' require_relative 'theme_runner' class Profiler LOG_LABEL = "Profiling: ".rjust(14).freeze REPORTS_DIR = File.expand_path('.memprof', __dir__).freeze def self.run puts yield new end def initia...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/theme_runner.rb
Ruby
mit
11,774
main
4,713
# frozen_string_literal: true # This profiler run simulates Shopify. # We are looking in the tests directory for liquid files and render them within the designated layout file. # We will also export a substantial database to liquid which the templates can render values of. # All this is to make the benchmark as non sy...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/profile.rb
Ruby
mit
11,774
main
716
# frozen_string_literal: true require 'stackprof' require_relative 'theme_runner' Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first profiler = ThemeRunner.new profiler.run [:cpu, :object].each do |profile_type| puts "Profiling in #{profile_type} mode..." results = StackProf.run(mode: profile_type) do...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/benchmark.rb
Ruby
mit
11,774
main
757
# frozen_string_literal: true require 'benchmark/ips' require_relative 'theme_runner' RubyVM::YJIT.enable if defined?(RubyVM::YJIT) Liquid::Environment.default.error_mode = ARGV.first.to_sym if ARGV.first profiler = ThemeRunner.new Benchmark.ips do |x| x.time = 20 x.warmup = 10 puts puts "Running benchma...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/money_filter.rb
Ruby
mit
11,774
main
310
# frozen_string_literal: true module MoneyFilter def money_with_currency(money) return '' if money.nil? format("$ %.2f USD", money / 100.0) end def money(money) return '' if money.nil? format("$ %.2f", money / 100.0) end private def currency ShopDrop.new.currency end end
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/database.rb
Ruby
mit
11,774
main
1,745
# frozen_string_literal: true require 'yaml' module Database DATABASE_FILE_PATH = "#{__dir__}/vision.database.yml" # Load the standard vision toolkit database and re-arrage it to be simply exportable # to liquid as assigns. All this is based on Shopify def self.tables @tables ||= begin db = ...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/shop_filter.rb
Ruby
mit
11,774
main
2,854
# frozen_string_literal: true module ShopFilter def asset_url(input) "/files/1/[shop_id]/[shop_id]/assets/#{input}" end def global_asset_url(input) "/global/#{input}" end def shopify_asset_url(input) "/shopify/#{input}" end def script_tag(url) %(<script src="#{url}" type="text/javascri...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/liquid.rb
Ruby
mit
11,774
main
731
# frozen_string_literal: true $LOAD_PATH.unshift(__dir__ + '/../../lib') require_relative '../../lib/liquid' require_relative 'comment_form' require_relative 'paginate' require_relative 'json_filter' require_relative 'money_filter' require_relative 'shop_filter' require_relative 'tag_filter' require_relative 'weight_...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/comment_form.rb
Ruby
mit
11,774
main
1,049
# frozen_string_literal: true class CommentForm < Liquid::Block Syntax = /(#{Liquid::VariableSignature}+)/ def initialize(tag_name, markup, options) super if markup =~ Syntax @variable_name = Regexp.last_match(1) @attributes = {} else raise SyntaxError, "Syntax Error in 'comment_...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/paginate.rb
Ruby
mit
11,774
main
2,557
# frozen_string_literal: true class Paginate < Liquid::Block Syntax = /(#{Liquid::QuotedFragment})\s*(by\s*(\d+))?/ def initialize(tag_name, markup, options) super if markup =~ Syntax @collection_name = Regexp.last_match(1) @page_size = if Regexp.last_match(2) Regexp.last_match(...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/shopify/tag_filter.rb
Ruby
mit
11,774
main
779
# frozen_string_literal: true module TagFilter def link_to_tag(label, tag) "<a title=\"Show tag #{tag}\" href=\"/collections/#{@context['handle']}/#{tag}\">#{label}</a>" end def highlight_active_tag(tag, css_class = 'active') if @context['current_tags'].include?(tag) "<span class=\"#{css_class}\">...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/unit/expression_benchmark.rb
Ruby
mit
11,774
main
1,551
# frozen_string_literal: true require "benchmark/ips" # benchmark liquid lexing require 'liquid' RubyVM::YJIT.enable STRING_MARKUPS = [ "\"foo\"", "\"fooooooooooo\"", "\"foooooooooooooooooooooooooooooo\"", "'foo'", "'fooooooooooo'", "'foooooooooooooooooooooooooooooo'", ] VARIABLE_MARKUPS = [ "articl...
github
Shopify/liquid
https://github.com/Shopify/liquid
performance/unit/lexer_benchmark.rb
Ruby
mit
11,774
main
654
# frozen_string_literal: true require "benchmark/ips" # benchmark liquid lexing require 'liquid' RubyVM::YJIT.enable EXPRESSIONS = [ "foo[1..2].baz", "12.0", "foo.bar.based", "21 - 62", "foo.bar.baz", "foo > 12", "foo < 12", "foo <= 12", "foo >= 12", "foo <> 12", "foo == 12", "foo != 12", ...
github
Shopify/liquid
https://github.com/Shopify/liquid
spec/ruby_liquid_with_active_support.rb
Ruby
mit
11,774
main
1,202
# frozen_string_literal: true # Liquid Spec Adapter for Shopify/liquid with ActiveSupport loaded # # Run with: bundle exec liquid-spec run spec/ruby_liquid_with_active_support.rb $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) require 'active_support/all' require 'liquid' LiquidSpec.configure do |config| #...
github
Shopify/liquid
https://github.com/Shopify/liquid
spec/ruby_liquid_lax.rb
Ruby
mit
11,774
main
977
# frozen_string_literal: true # Liquid Spec Adapter for Shopify/liquid with lax parsing mode # # Run with: bundle exec liquid-spec run spec/ruby_liquid_lax.rb $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) require 'liquid' LiquidSpec.configure do |config| config.features = [:core, :lax_parsing] end # Com...
github
Shopify/liquid
https://github.com/Shopify/liquid
spec/ruby_liquid.rb
Ruby
mit
11,774
main
1,107
# frozen_string_literal: true # Liquid Spec Adapter for Shopify/liquid (Ruby reference implementation) # # Run with: bundle exec liquid-spec run spec/ruby_liquid.rb $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) require 'liquid' LiquidSpec.configure do |config| # Run core Liquid specs config.features = ...
github
Shopify/liquid
https://github.com/Shopify/liquid
spec/ruby_liquid_yjit.rb
Ruby
mit
11,774
main
1,155
# frozen_string_literal: true # Liquid Spec Adapter for Shopify/liquid with YJIT + strict mode + ActiveSupport # # Run with: bundle exec liquid-spec run spec/ruby_liquid_yjit.rb $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) # Enable YJIT if available if defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:e...
github
Shopify/liquid
https://github.com/Shopify/liquid
example/server/liquid_servlet.rb
Ruby
mit
11,774
main
716
# frozen_string_literal: true class LiquidServlet < WEBrick::HTTPServlet::AbstractServlet def do_GET(req, res) handle(:get, req, res) end def do_POST(req, res) handle(:post, req, res) end private def handle(_type, req, res) @request = req @response = res @request.path_info =~ /(\w+...
github
Shopify/liquid
https://github.com/Shopify/liquid
example/server/example_servlet.rb
Ruby
mit
11,774
main
1,493
# frozen_string_literal: true module ProductsFilter def price(integer) format("$%.2d USD", integer / 100.0) end def prettyprint(text) text.gsub(/\*(.*)\*/, '<b>\1</b>') end def count(array) array.size end def paragraph(p) "<p>#{p}</p>" end end class Servlet < LiquidServlet def ind...
github
Shopify/liquid
https://github.com/Shopify/liquid
example/server/server.rb
Ruby
mit
11,774
main
325
# frozen_string_literal: true require 'webrick' require 'rexml/document' require_relative '../../lib/liquid' require_relative 'liquid_servlet' require_relative 'example_servlet' # Setup webrick server = WEBrick::HTTPServer.new(Port: ARGV[1] || 3000) server.mount('/', Servlet) trap("INT") { server.shutdown } server.s...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/test_helper.rb
Ruby
mit
11,774
main
5,403
#!/usr/bin/env ruby # frozen_string_literal: true ENV["MT_NO_EXPECTATIONS"] = "1" require 'minitest/autorun' $LOAD_PATH.unshift(File.join(File.expand_path(__dir__), '..', 'lib')) require 'liquid.rb' require 'liquid/profiler' mode = :strict if (env_mode = ENV['LIQUID_PARSER_MODE']) puts "-- #{env_mode.upcase} ERROR...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/parse_tree_visitor_test.rb
Ruby
mit
11,774
main
5,052
# frozen_string_literal: true require 'test_helper' class ParseTreeVisitorTest < Minitest::Test include Liquid def test_variable assert_equal( ["test"], visit(%({{ test }})), ) end def test_varible_with_filter assert_equal( ["test", "infilter"], visit(%({{ test | split: i...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/lexer_unit_test.rb
Ruby
mit
11,774
main
3,599
# frozen_string_literal: true require 'test_helper' class LexerUnitTest < Minitest::Test include Liquid def test_strings assert_equal( [[:string, %('this is a test""')], [:string, %("wat 'lol'")], [:end_of_string]], tokenize(%( 'this is a test""' "wat 'lol'")), ) end def test_integer ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/resource_limits_unit_test.rb
Ruby
mit
11,774
main
2,689
# frozen_string_literal: true require 'test_helper' class ResourceLimitsUnitTest < Minitest::Test def test_cumulative_scores_initialize_to_zero limits = Liquid::ResourceLimits.new({}) assert_equal(0, limits.cumulative_render_score) assert_equal(0, limits.cumulative_assign_score) end def test_cumula...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/environment_test.rb
Ruby
mit
11,774
main
675
# frozen_string_literal: true require 'test_helper' class EnvironmentTest < Minitest::Test include Liquid class UnsubscribeFooter < Liquid::Tag def render(_context) 'Unsubscribe Footer' end end def test_custom_tag email_environment = Liquid::Environment.build do |environment| environ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/block_unit_test.rb
Ruby
mit
11,774
main
2,131
# frozen_string_literal: true require 'test_helper' class BlockUnitTest < Minitest::Test include Liquid def test_blankspace template = Liquid::Template.parse(" ") assert_equal([" "], template.root.nodelist) end def test_variable_beginning template = Liquid::Template.parse("{{funk}} ") ass...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tag_unit_test.rb
Ruby
mit
11,774
main
1,075
# frozen_string_literal: true require 'test_helper' class TagUnitTest < Minitest::Test include Liquid def test_tag tag = Tag.parse('tag', "", new_tokenizer, ParseContext.new) assert_equal('liquid::tag', tag.name) assert_equal('', tag.render(Context.new)) end def test_return_raw_text_of_tag t...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/partial_cache_unit_test.rb
Ruby
mit
11,774
main
5,401
# frozen_string_literal: true require 'test_helper' class PartialCacheUnitTest < Minitest::Test def test_uses_the_file_system_register_if_present context = Liquid::Context.build( registers: { file_system: StubFileSystem.new('my_partial' => 'my partial body'), }, ) partial = Liquid::...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/parser_unit_test.rb
Ruby
mit
11,774
main
2,404
# frozen_string_literal: true require 'test_helper' class ParserUnitTest < Minitest::Test include Liquid def test_consume p = new_parser("wat: 7") assert_equal('wat', p.consume(:id)) assert_equal(':', p.consume(:colon)) assert_equal('7', p.consume(:number)) end def test_jump p = new_pars...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/template_factory_unit_test.rb
Ruby
mit
11,774
main
279
# frozen_string_literal: true require 'test_helper' class TemplateFactoryUnitTest < Minitest::Test include Liquid def test_for_returns_liquid_template_instance template = TemplateFactory.new.for("anything") assert_instance_of(Liquid::Template, template) end end
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/regexp_unit_test.rb
Ruby
mit
11,774
main
2,226
# frozen_string_literal: true require 'test_helper' require 'timeout' class RegexpUnitTest < Minitest::Test include Liquid def test_empty assert_equal([], ''.scan(QuotedFragment)) end def test_quote assert_equal(['"arg 1"'], '"arg 1"'.scan(QuotedFragment)) end def test_words assert_equal(['...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/variable_unit_test.rb
Ruby
mit
11,774
main
8,001
# frozen_string_literal: true require 'test_helper' class VariableUnitTest < Minitest::Test include Liquid def test_variable var = create_variable('hello') assert_equal(VariableLookup.new('hello'), var.name) end def test_filters var = create_variable('hello | textileze') assert_equal(Variabl...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/strainer_template_unit_test.rb
Ruby
mit
11,774
main
2,388
# frozen_string_literal: true require 'test_helper' class StrainerTemplateUnitTest < Minitest::Test include Liquid def test_add_filter_when_wrong_filter_class c = Context.new s = c.strainer wrong_filter = lambda(&:reverse) exception = assert_raises(TypeError) do s.class.add_filter(wrong_fi...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/i18n_unit_test.rb
Ruby
mit
11,774
main
965
# frozen_string_literal: true require 'test_helper' class I18nUnitTest < Minitest::Test include Liquid def setup @i18n = I18n.new(fixture("en_locale.yml")) end def test_simple_translate_string assert_equal("less is more", @i18n.translate("simple")) end def test_nested_translate_string asser...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/parse_context_unit_test.rb
Ruby
mit
11,774
main
4,131
# frozen_string_literal: true require 'test_helper' class ParseContextUnitTest < Minitest::Test include Liquid def test_safe_parse_expression_with_variable_lookup parser_strict = strict_parse_context.new_parser('product.title') result_strict = strict_parse_context.safe_parse_expression(parser_strict) ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/condition_unit_test.rb
Ruby
mit
11,774
main
14,242
# frozen_string_literal: true require 'test_helper' class ConditionUnitTest < Minitest::Test include Liquid def setup @context = Liquid::Context.new end def test_basic_condition assert_equal(false, Condition.new(1, '==', 2).evaluate(Context.new)) assert_equal(true, Condition.new(1, '==', 1).eva...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/environment_filter_test.rb
Ruby
mit
11,774
main
3,354
# frozen_string_literal: true require 'test_helper' class EnvironmentFilterTest < Minitest::Test include Liquid module AccessScopeFilters def public_filter "public" end def private_filter "private" end private :private_filter end module LateAddedFilter def late_added_fil...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tokenizer_unit_test.rb
Ruby
mit
11,774
main
2,617
# frozen_string_literal: true require 'test_helper' class TokenizerTest < Minitest::Test def test_tokenize_strings assert_equal([' '], tokenize(' ')) assert_equal(['hello world'], tokenize('hello world')) assert_equal(['{}'], tokenize('{}')) end def test_tokenize_variables assert_equal(['{{funk...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/registers_unit_test.rb
Ruby
mit
11,774
main
4,335
# frozen_string_literal: true require 'test_helper' class RegistersUnitTest < Minitest::Test include Liquid def test_set static_register = Registers.new(a: 1, b: 2) static_register[:b] = 22 static_register[:c] = 33 assert_equal(1, static_register[:a]) assert_equal(22, static_register[:b]) ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/file_system_unit_test.rb
Ruby
mit
11,774
main
1,105
# frozen_string_literal: true require 'test_helper' class FileSystemUnitTest < Minitest::Test include Liquid def test_default assert_raises(FileSystemError) do BlankFileSystem.new.read_template_file("dummy") end end def test_local file_system = Liquid::LocalFileSystem.new("/some/path") ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/template_unit_test.rb
Ruby
mit
11,774
main
1,320
# frozen_string_literal: true require 'test_helper' class TemplateUnitTest < Minitest::Test include Liquid def test_sets_default_localization_in_document t = Template.new t.parse('{%comment%}{%endcomment%}') assert_instance_of(I18n, t.root.nodelist[0].options[:locale]) end def test_sets_default_...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tags/case_tag_unit_test.rb
Ruby
mit
11,774
main
3,701
# frozen_string_literal: true require 'test_helper' class CaseTagUnitTest < Minitest::Test include Liquid def test_case_nodelist template = Liquid::Template.parse('{% case var %}{% when true %}WHEN{% else %}ELSE{% endcase %}') assert_equal(['WHEN', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodeli...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tags/doc_tag_unit_test.rb
Ruby
mit
11,774
main
7,302
# frozen_string_literal: true require 'test_helper' class DocTagUnitTest < Minitest::Test def test_doc_tag template = <<~LIQUID.chomp {% doc %} Renders loading-spinner. @param {string} foo - some foo @param {string} [bar] - optional bar @example {% render 'loading...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tags/comment_tag_unit_test.rb
Ruby
mit
11,774
main
4,898
# frozen_string_literal: true require 'test_helper' class CommentTagUnitTest < Minitest::Test def test_comment_inside_liquid_tag assert_template_result("", <<~LIQUID.chomp) {% liquid if 1 != 1 comment else echo 123 endcomment endif %} LIQUID en...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tags/if_tag_unit_test.rb
Ruby
mit
11,774
main
299
# frozen_string_literal: true require 'test_helper' class IfTagUnitTest < Minitest::Test def test_if_nodelist template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}') assert_equal(['IF', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten) end end
github
Shopify/liquid
https://github.com/Shopify/liquid
test/unit/tags/for_tag_unit_test.rb
Ruby
mit
11,774
main
516
# frozen_string_literal: true require 'test_helper' class ForTagUnitTest < Minitest::Test def test_for_nodelist template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}') assert_equal(['FOR'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten) end def test_for_else_nodelist ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/block_test.rb
Ruby
mit
11,774
main
1,514
# frozen_string_literal: true require 'test_helper' class BlockTest < Minitest::Test include Liquid def test_unexpected_end_tag source = '{% if true %}{% endunless %}' assert_match_syntax_error("Liquid syntax error (line 1): 'endunless' is not a valid delimiter for if tags. use endif", source) end d...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/assign_test.rb
Ruby
mit
11,774
main
4,646
# frozen_string_literal: true require 'test_helper' class AssignTest < Minitest::Test include Liquid def test_assign_with_hyphen_in_variable_name template_source = <<~END_TEMPLATE {% assign this-thing = 'Print this-thing' -%} {{ this-thing -}} END_TEMPLATE assert_template_result("Print th...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/hash_ordering_test.rb
Ruby
mit
11,774
main
494
# frozen_string_literal: true require 'test_helper' class HashOrderingTest < Minitest::Test module MoneyFilter def money(input) format(' %d$ ', input) end end module CanadianMoneyFilter def money(input) format(' %d$ CAD ', input) end end include Liquid def test_global_regist...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/trim_mode_test.rb
Ruby
mit
11,774
main
11,558
# frozen_string_literal: true require 'test_helper' class TrimModeTest < Minitest::Test include Liquid # Make sure the trim isn't applied to standard output def test_standard_output text = <<-END_TEMPLATE <div> <p> {{ 'John' }} </p> </div> END_TEMPLATE expected...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/parsing_quirks_test.rb
Ruby
mit
11,774
main
5,064
# frozen_string_literal: true require 'test_helper' class ParsingQuirksTest < Minitest::Test include Liquid def test_parsing_css text = " div { font-weight: bold; } " assert_equal(text, Template.parse(text).render!) end def test_raise_on_single_close_bracet assert_raises(SyntaxError) do Te...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/filter_test.rb
Ruby
mit
11,774
main
5,675
# frozen_string_literal: true require 'test_helper' module MoneyFilter def money(input) format(' %d$ ', input) end def money_with_underscore(input) format(' %d$ ', input) end end module CanadianMoneyFilter def money(input) format(' %d$ CAD ', input) end end module SubstituteFilter def sub...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/document_test.rb
Ruby
mit
11,774
main
419
# frozen_string_literal: true require 'test_helper' class DocumentTest < Minitest::Test include Liquid def test_unexpected_outer_tag source = "{% else %}" assert_match_syntax_error("Liquid syntax error (line 1): Unexpected outer 'else' tag", source) end def test_unknown_tag source = "{% foo %}" ...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/error_handling_test.rb
Ruby
mit
11,774
main
11,167
# frozen_string_literal: true require 'test_helper' class ErrorHandlingTest < Minitest::Test include Liquid def test_templates_parsed_with_line_numbers_renders_them_in_errors template = <<-LIQUID Hello, {{ errors.standard_error }} will raise a standard error. Bla bla test. {{ error...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/tag_test.rb
Ruby
mit
11,774
main
1,098
# frozen_string_literal: true require 'test_helper' class TagTest < Minitest::Test include Liquid def test_custom_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility klass1 = Class.new(Tag) do def render(*) 'hello' end end with_custom_tag('blabla', klas...
github
Shopify/liquid
https://github.com/Shopify/liquid
test/integration/expression_test.rb
Ruby
mit
11,774
main
5,192
# frozen_string_literal: true require 'test_helper' require 'lru_redux' class ExpressionTest < Minitest::Test def test_keyword_literals assert_template_result("true", "{{ true }}") assert_expression_result(true, "true") end def test_string assert_template_result("single quoted", "{{'single quoted'}...