Merge pull request #1951 from jens-na/include-tag-error-path
This commit is contained in:
		
						commit
						05df50f929
					
				| 
						 | 
					@ -102,7 +102,7 @@ eos
 | 
				
			||||||
        validate_file_name(file)
 | 
					        validate_file_name(file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        path = File.join(dir, file)
 | 
					        path = File.join(dir, file)
 | 
				
			||||||
        validate_file(path, context.registers[:site].safe)
 | 
					        validate_file(context.registers[:site].source, path, context.registers[:site].safe)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        begin
 | 
					        begin
 | 
				
			||||||
          partial = Liquid::Template.parse(source(path, context))
 | 
					          partial = Liquid::Template.parse(source(path, context))
 | 
				
			||||||
| 
						 | 
					@ -122,11 +122,12 @@ eos
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def validate_file(file, safe)
 | 
					      def validate_file(sourcedir, file, safe)
 | 
				
			||||||
 | 
					        relative_file = Pathname.new(file).relative_path_from(Pathname.new(sourcedir))
 | 
				
			||||||
        if !File.exists?(file)
 | 
					        if !File.exists?(file)
 | 
				
			||||||
          raise IOError.new "Included file '#{file}' not found" 
 | 
					          raise IOError.new "Included file '#{relative_file}' not found" 
 | 
				
			||||||
        elsif File.symlink?(file) && safe
 | 
					        elsif File.symlink?(file) && safe
 | 
				
			||||||
          raise IOError.new "The included file '#{file}' should not be a symlink"
 | 
					          raise IOError.new "The included file '#{relative_file}' should not be a symlink"
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -487,6 +487,25 @@ CONTENT
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "include missing file" do
 | 
				
			||||||
 | 
					      setup do
 | 
				
			||||||
 | 
					        @content = <<CONTENT
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					title: missing file
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% include missing.html %}
 | 
				
			||||||
 | 
					CONTENT
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      should "raise error relative to source directory" do
 | 
				
			||||||
 | 
					        exception = assert_raise IOError do
 | 
				
			||||||
 | 
					          create_post(@content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        assert_equal 'Included file \'_includes/missing.html\' not found', exception.message
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    context "include tag with variable and liquid filters" do
 | 
					    context "include tag with variable and liquid filters" do
 | 
				
			||||||
      setup do
 | 
					      setup do
 | 
				
			||||||
        stub(Jekyll).configuration do
 | 
					        stub(Jekyll).configuration do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue