Skip to content
Browse files

fixes variables and root path in Local File system

there were a couple of variables that were named wrong cause the local
file system not to work.

also root was being calculated wrong in test. i now only allow web
paths to be set for the local file system. the file system will
then translate to the file system path with the use of expandPath().

also wrote some test coverage since there wasn't any done during the
initial port.
  • Loading branch information...
1 parent 3bea14d commit 9073ac4fa1d67a23e6feb55dd405aad9b494bc64 Tony Petruzzi committed May 21, 2012
Showing with 50 additions and 14 deletions.
  1. +22 −11 lib/liquid/LiquidLocalFileSystem.cfc
  2. +2 −2 tests/index.cfm
  3. +25 −1 tests/tests/FileSystemTest.cfc
  4. +1 −0 tests/tests/templates/_template.liquid
View
33 lib/liquid/LiquidLocalFileSystem.cfc
@@ -3,7 +3,7 @@
<cffunction name="init">
<cfargument name="root" type="string" required="true">
- <cfset this._root = ListChangeDelims(arguments.root, "/", "\")>
+ <cfset this.root = ListChangeDelims(arguments.root, "/", "\")>
<cfreturn this>
</cffunction>
@@ -12,8 +12,8 @@
<cfargument name="template_path" type="string" required="true">
<cfset var loc = {}>
- <cfset loc.full_path = this.full_path(arguments.templatePath)>
- <cffile action="read" file="#loc.fullpath#" variable="loc.contents">
+ <cfset loc.full_path = this.full_path(arguments.template_path)>
+ <cffile action="read" file="#ExpandPath(loc.full_path)#" variable="loc.contents">
<cfreturn loc.contents>
</cffunction>
@@ -22,22 +22,33 @@
<cfargument name="template_path" type="string" required="true">
<cfset var loc = {}>
- <cfset loc.name_regex = createObject("component", "LiquidRegexp").init('^[^.\/][a-zA-Z0-9_\/]+$')>
+ <cfset loc.name_regex = createObject("component", "LiquidRegexp").init('^[^\.\/][a-zA-Z0-9_\/]+$')>
<cfif !loc.name_regex.match(arguments.template_path)>
- <cfset createObject("component", "LiquidException").init("Illegal template name 'arguments.template_path'")>
+ <cfset createObject("component", "LiquidException").init("Illegal template name '#arguments.template_path#'")>
</cfif>
<cfif FindNoCase('/', arguments.template_path) neq 0>
- <cfset loc.full_path = [this._root, GetDirectoryFromPath(arguments.template_path), "#application.LiquidConfig.LIQUID_INCLUDE_PREFIX##ListLast(arguments.template_path, '/')#.#application.LiquidConfig.LIQUID_INCLUDE_SUFFIX#"]>
+ <cfset loc.full_path = [GetDirectoryFromPath(arguments.template_path), "#application.LiquidConfig.LIQUID_INCLUDE_PREFIX##ListLast(arguments.template_path, '/')#.#application.LiquidConfig.LIQUID_INCLUDE_SUFFIX#"]>
<cfelse>
- <cfset loc.full_path = [this._root, "#application.LiquidConfig.LIQUID_INCLUDE_PREFIX##arguments.template_path#.#application.LiquidConfig.LIQUID_INCLUDE_SUFFIX#"]>
+ <cfset loc.full_path = ["#application.LiquidConfig.LIQUID_INCLUDE_PREFIX##arguments.template_path#.#application.LiquidConfig.LIQUID_INCLUDE_SUFFIX#"]>
</cfif>
- <cfset loc.full_path = ListChangeDelims(ArrayToList(loc.full_path, "/"), "/", "/")>
- <cfif left(loc.full_path, len(this._root)) neq this._root>
- <cfset createObject("component", "LiquidException").init("Illegal template path #loc.full_path#")>
- </cfif>
+ <cfset loc.full_path = this.root & ListChangeDelims(ArrayToList(loc.full_path, "/"), "/", "/")>
+
+ <!--- convert to full path --->
+ <cftry>
+ <cfset loc._full_path = ExpandPath(loc.full_path)>
+ <cfset loc._root = ExpandPath(this.root)>
+
+ <cfif left(loc._full_path, len(loc._root)) neq loc._root>
+ <cfset createObject("component", "LiquidException").init("Illegal template path #loc.full_path#")>
+ </cfif>
+
+ <cfcatch type="any">
+ <cfset createObject("component", "LiquidException").init("Illegal template path #loc.full_path#")>
+ </cfcatch>
+ </cftry>
<cfreturn loc.full_path>
</cffunction>
View
4 tests/index.cfm
@@ -14,8 +14,8 @@
<cfelse>
- <cfset test = createObject("component", "cfml-liquid.tests.tests.LiquidFiltersInTemplate")>
- <cfset test.runTest("test", "TEST_LOCAL_GLOBAL")>
+ <cfset test = createObject("component", "cfml-liquid.tests.tests.FileSystemTest")>
+ <cfset test.runTest("test", "test_read_local_template")>
</cfif>
View
26 tests/tests/FileSystemTest.cfc
@@ -12,9 +12,21 @@
</cftry>
</cffunction>
+ <cffunction name="test_root">
+ <cfset loc.root = '/cfml-liquid/tests/tests/templates/'>
+
+ <cfset loc.file_system = createObject("component", "cfml-liquid.lib.liquid.LiquidLocalFileSystem").init(loc.root)>
+
+ <cfset loc.root = ListChangeDelims(loc.root, "/", "\")>
+
+ <cfset loc.r = loc.file_system.root>
+ <cfset loc.e = loc.root>
+
+ <cfset assert('loc.e eq loc.r')>
+ </cffunction>
<cffunction name="test_local">
- <cfset loc.root = expandPath(".") & '/templates/'>
+ <cfset loc.root = '/cfml-liquid/tests/tests/templates/'>
<cfset loc.root = ListChangeDelims(loc.root, "/", "\")>
<cfset loc.file_system = createObject("component", "cfml-liquid.lib.liquid.LiquidLocalFileSystem").init(loc.root)>
@@ -56,4 +68,16 @@
</cffunction>
+ <cffunction name="test_read_local_template">
+ <cfset loc.root = '/cfml-liquid/tests/tests/templates/'>
+ <cfset loc.root = ListChangeDelims(loc.root, "/", "\")>
+
+ <cfset loc.file_system = createObject("component", "cfml-liquid.lib.liquid.LiquidLocalFileSystem").init(loc.root)>
+
+ <cfset loc.e = "Put Liquid Markup here">
+ <cfset loc.r = loc.file_system.read_template_file('template')>
+
+ <cfset assert('loc.e eq loc.r')>
+ </cffunction>
+
</cfcomponent>
View
1 tests/tests/templates/_template.liquid
@@ -0,0 +1 @@
+Put Liquid Markup here

0 comments on commit 9073ac4

Please sign in to comment.
Something went wrong with that request. Please try again.