From beed46e212422d12e39f279dbafedf2a7e9ad90f Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 19 Feb 2024 16:49:35 +0100 Subject: [PATCH] LDEV-4081 - modify FileWrite --- .../lucee/runtime/functions/file/FileWrite.java | 14 ++++++++------ loader/build.xml | 2 +- loader/pom.xml | 2 +- test/tickets/LDEV4081.cfc | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/lucee/runtime/functions/file/FileWrite.java b/core/src/main/java/lucee/runtime/functions/file/FileWrite.java index 444fdd5f04..96974f9865 100755 --- a/core/src/main/java/lucee/runtime/functions/file/FileWrite.java +++ b/core/src/main/java/lucee/runtime/functions/file/FileWrite.java @@ -26,6 +26,7 @@ import lucee.runtime.PageContext; import lucee.runtime.PageContextImpl; import lucee.runtime.PageSourcePool; +import lucee.runtime.exp.FunctionException; import lucee.runtime.exp.PageException; import lucee.runtime.op.Caster; @@ -50,14 +51,15 @@ public static String call(PageContext pc, Object obj, Object data, String charse res = Caster.toResource(pc, obj, false); pc.getConfig().getSecurityManager().checkFileLocation(res); Resource parent = res.getParentResource(); - // if (parent != null && !parent.exists()) throw new FunctionException(pc, "FileWrite", 1, "source", - // "parent directory for [" + res + "] doesn't exist"); + if (parent != null && !parent.exists()) throw new FunctionException(pc, "FileWrite", 1, "source", "parent directory for [" + res + "] doesn't exist"); fsw = new FileStreamWrapperWrite(res, charset, false, false); } - fsw.write(data); - } - catch (IOException e) { - throw Caster.toPageException(e); + try { + fsw.write(data); + } + catch (IOException e) { + throw new FunctionException(pc, "FileWrite", 1, "source", "Invalid file [" + Caster.toResource(pc, obj, false) + "]", e.getMessage()); + } } finally { if (close) IOUtil.closeEL(fsw); diff --git a/loader/build.xml b/loader/build.xml index 31eff3dad1..f3a60d0b68 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index f653a5aa45..7049cb7d5c 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.0.49-SNAPSHOT + 6.1.0.50-SNAPSHOT jar Lucee Loader Build diff --git a/test/tickets/LDEV4081.cfc b/test/tickets/LDEV4081.cfc index 1134946435..75242cca19 100644 --- a/test/tickets/LDEV4081.cfc +++ b/test/tickets/LDEV4081.cfc @@ -1,4 +1,4 @@ -component extends="org.lucee.cfml.test.LuceeTestCase" skip="true" { +component extends="org.lucee.cfml.test.LuceeTestCase" { function run( testResults , testBox ) { describe( "Test case for LDEV-4081", function() {