File: jekyll-sanitize-path

package info (click to toggle)
jekyll 4.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: ruby: 16,765; javascript: 1,455; sh: 214; xml: 29; makefile: 9
file content (46 lines) | stat: -rwxr-xr-x 1,567 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby

require_relative '../lib/jekyll'
require 'benchmark/ips'

base_directory = Dir.pwd

Benchmark.ips do |x|
  #
  # Does not include the base_directory
  #
  x.report('with no questionable path') do
    Jekyll.sanitized_path(base_directory, '')
  end
  x.report('with a single-part questionable path') do
    Jekyll.sanitized_path(base_directory, 'thingy')
  end
  x.report('with a multi-part questionable path') do
    Jekyll.sanitized_path(base_directory, 'thingy/in/my/soup')
  end
  x.report('with a single-part traversal path') do
    Jekyll.sanitized_path(base_directory, '../thingy')
  end
  x.report('with a multi-part traversal path') do
    Jekyll.sanitized_path(base_directory, '../thingy/in/my/../../soup')
  end

  #
  # Including the base_directory
  #
  x.report('with the exact same paths') do
    Jekyll.sanitized_path(base_directory, base_directory)
  end
  x.report('with a single-part absolute path including the base_directory') do
    Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy'))
  end
  x.report('with a multi-part absolute path including the base_directory') do
    Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/in/my/soup'))
  end
  x.report('with a single-part traversal path including the base_directory') do
    Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/..'))
  end
  x.report('with a multi-part traversal path including the base_directory') do
    Jekyll.sanitized_path(base_directory, File.join('thingy/in/my/../../soup'))
  end
end