Skip to content

Commit aa3c3aa

Browse files
committed
LDEV-6172 fix physicalFirst override in MappingImpl lazy init
1 parent 35ed957 commit aa3c3aa

6 files changed

Lines changed: 41 additions & 7 deletions

File tree

core/src/main/java/lucee/runtime/MappingImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private void initPhysical() {
183183
if (physical == null && strPhysical != null) {
184184
ServletContext cs = (config instanceof ConfigWeb) ? ((ConfigWeb) config).getServletContext() : null;
185185
physical = ConfigWebUtil.getResource(cs, strPhysical, config.getConfigDir(), FileUtil.TYPE_DIR, config, checkPhysicalFromWebroot, false);
186-
if (archive == null) this.physicalFirst = true;
186+
if (strArchive == null) this.physicalFirst = true;
187187
else if (physical == null) this.physicalFirst = false;
188188
}
189189
}
@@ -210,8 +210,8 @@ private void initArchive() {
210210
tmp = null;
211211
}
212212

213-
if (tmp == null) this.physicalFirst = true;
214-
else if (physical == null) this.physicalFirst = false;
213+
if (tmp == null && strPhysical != null) this.physicalFirst = true;
214+
else if (strPhysical == null) this.physicalFirst = false;
215215
archive = tmp;
216216
}
217217
}

loader/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="core" basedir="." name="Lucee"
33
xmlns:resolver="antlib:org.apache.maven.resolver.ant">
44

5-
<property name="version" value="6.2.6.5-SNAPSHOT"/>
5+
<property name="version" value="6.2.6.6-SNAPSHOT"/>
66

77
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
88
<classpath>

loader/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.lucee</groupId>
55
<artifactId>lucee</artifactId>
6-
<version>6.2.6.5-SNAPSHOT</version>
6+
<version>6.2.6.6-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>Lucee Loader Build</name>

test/general/Archives.cfc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="archive,mapping" {
2323
_buildHybridPhysicalFirst();
2424
_buildMissingPhysical();
2525
_buildMissingArchive();
26+
_buildCorruptArchive();
2627
}
2728

2829
function afterAll() {
@@ -73,8 +74,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="archive,mapping" {
7374

7475
describe( "Hybrid physical + archive with primary=archive", function() {
7576

76-
it( title="should prefer archive over physical when primary is archive", skip=true, body=function() {
77-
// LDEV-6172: initPhysical() overrides physicalFirst before archive init
77+
it( title="should prefer archive over physical when primary is archive", body=function() {
7878
var result = _internalRequest(
7979
template: "#_uri()#/hybrid/index.cfm",
8080
urls: { scene: "archive" }
@@ -130,6 +130,17 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="archive,mapping" {
130130

131131
});
132132

133+
describe( "Graceful fallback when archive is corrupt", function() {
134+
135+
it( "should fall back to physical when archive is not a valid LAR", function() {
136+
var result = _internalRequest(
137+
template: "#_uri()#/corruptArchive/index.cfm"
138+
);
139+
expect( result.fileContent.trim() ).toBe( "from-physical" );
140+
});
141+
142+
});
143+
133144
}
134145

135146
// ---- archive builders ----
@@ -244,6 +255,17 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="archive,mapping" {
244255
// intentionally do NOT create physDir
245256
}
246257

258+
private function _buildCorruptArchive() {
259+
var corruptLar = variables.testDir & "corrupt.lar";
260+
var physDir = variables.testDir & "corruptArchive-physical/";
261+
262+
// write garbage bytes — not a valid JAR/ZIP
263+
fileWrite( corruptLar, repeatString( "NOT A VALID LAR FILE", 100 ) );
264+
265+
directoryCreate( physDir, true, true );
266+
fileWrite( physDir & "hello.cfm", "<cfset writeOutput( 'from-physical' )>" );
267+
}
268+
247269
private function _buildMissingArchive() {
248270
// archive path points to a non-existent .lar, physical is valid
249271
var physDir = variables.testDir & "missingArchive-physical/";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
component {
2+
3+
variables.testDir = getTempDirectory() & "archivesTest/";
4+
5+
this.mappings[ "/corruptArchiveLib" ] = {
6+
physical: variables.testDir & "corruptArchive-physical/",
7+
archive: variables.testDir & "corrupt.lar",
8+
primary: "archive"
9+
};
10+
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<cfinclude template="/corruptArchiveLib/hello.cfm">

0 commit comments

Comments
 (0)