Skip to content

Commit

Permalink
Merge branch '6.2' into 7.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	loader/build.xml
#	loader/pom.xml
  • Loading branch information
michaeloffner committed Dec 9, 2024
2 parents 548a1f0 + 75c6dd2 commit 34c5100
Show file tree
Hide file tree
Showing 55 changed files with 295 additions and 197 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/cache/CacheUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public static Struct getInfo(Struct info, CacheEntry ce) {
}

public static Struct getInfo(Cache c) {
return getInfo(new StructImpl(), c);
return getInfo(new StructImpl(StructImpl.TYPE_SYNC), c);
}

public static Struct getInfo(Struct info, Cache c) {
if (info == null) info = new StructImpl();
if (info == null) info = new StructImpl(StructImpl.TYPE_SYNC);
try {
long value = c.hitCount();
if (value >= 0) info.setEL("hit_count", Double.valueOf(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
package lucee.runtime.functions.international;

import java.lang.ref.SoftReference;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import lucee.runtime.PageContext;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.exp.ExpressionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.Function;
Expand All @@ -41,14 +44,16 @@ public final class LSParseNumber implements Function {
private static Map<Locale, SoftReference<NumberFormat>> formatters = new ConcurrentHashMap<Locale, SoftReference<NumberFormat>>();

public static Number call(PageContext pc, String string) throws PageException {
return toDoubleValue(pc.getLocale(), string);
if (ThreadLocalPageContext.preciseMath(pc)) return toBigDecimal(pc.getLocale(), string);
return toDouble(pc.getLocale(), string);
}

public static Number call(PageContext pc, String string, Locale locale) throws PageException {
return toDoubleValue(locale == null ? pc.getLocale() : locale, string);
if (ThreadLocalPageContext.preciseMath(pc)) return toBigDecimal(locale == null ? pc.getLocale() : locale, string);
return toDouble(locale == null ? pc.getLocale() : locale, string);
}

public static double toDoubleValue(Locale locale, String str) throws PageException {
public static Number toDouble(Locale locale, String str) throws PageException {
SoftReference<NumberFormat> tmp = formatters.remove(locale);
NumberFormat nf = tmp == null ? null : tmp.get();
if (nf == null) {
Expand All @@ -71,6 +76,30 @@ public static double toDoubleValue(Locale locale, String str) throws PageExcepti
}
}

public static BigDecimal toBigDecimal(Locale locale, String str) throws PageException {
DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(locale);
df.setParseBigDecimal(true);

try {
str = optimze(str.toCharArray());

ParsePosition pp = new ParsePosition(0);
BigDecimal result = (BigDecimal) df.parse(str, pp);

if (pp.getIndex() < str.length()) {
throw new ExpressionException("Can't parse String [" + str + "] against locale [" + LocaleFactory.getDisplayName(locale) + "] to a BigDecimal");
}
if (result == null) {
throw new ExpressionException("Can't parse String [" + str + "] against locale [" + LocaleFactory.getDisplayName(locale) + "] to a BigDecimal");
}

return result;
}
finally {
// No caching here, but you could implement caching if necessary
}
}

private static String optimze(char[] carr) {
StringBuilder sb = new StringBuilder();
char c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public static Number call(PageContext pc, String strNumber) throws PageException
}

public static Number call(PageContext pc, String strNumber, String strRadix) throws PageException {
return invoke(strNumber, strRadix);
return invoke(pc, strNumber, strRadix);
}

public static Number invoke(String strNumber, String strRadix, Number defaultValue) {
public static Number invoke(PageContext pc, String strNumber, String strRadix, Number defaultValue) {
try {
return invoke(strNumber, strRadix);
return invoke(pc, strNumber, strRadix);
}
catch (PageException e) {
return defaultValue;
}
}

public static Number invoke(String strNumber, String strRadix) throws PageException {
public static Number invoke(PageContext pc, String strNumber, String strRadix) throws PageException {
strNumber = strNumber.trim();
int radix = DEC;
if (strRadix == null) {
Expand Down Expand Up @@ -85,7 +85,7 @@ else if (strRadix.startsWith("hex")) {
if (strNumber.indexOf('.') != -1 && radix != DEC) throw new ExpressionException("The radix con only be [dec] for floating point numbers");

if (radix == DEC) {
return Caster.toDoubleValue(strNumber);
return Caster.toNumber(pc, strNumber);
}
return Integer.parseInt(strNumber, radix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static RegistryEntry[] filter(String string, String branch, short type)
String _value = StringUtil.substringEL(line, index + len + 1, "").trim();

if (_key.equals(NO_NAME)) _key = "";
if (_type == RegistryEntry.TYPE_DWORD) _value = String.valueOf(ParseNumber.invoke(_value.substring(2), "hex", 0));
if (_type == RegistryEntry.TYPE_DWORD) _value = String.valueOf(ParseNumber.invoke(null, _value.substring(2), "hex", 0));
RegistryEntry re = new RegistryEntry(_type, _key, _value);
if (type == RegistryEntry.TYPE_ANY || type == re.getType()) array.add(re);
// }
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/type/StructImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class StructImpl extends StructSupport {
public static final int DEFAULT_TYPE;

static {
DEFAULT_TYPE = StructNew.toType(SystemUtil.getSystemPropOrEnvVar("lucee.struct.type", null), TYPE_REGULAR);
DEFAULT_TYPE = StructNew.toType(SystemUtil.getSystemPropOrEnvVar("lucee.struct.type", null), TYPE_SYNC);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="7.0.0.66-SNAPSHOT"/>
<property name="version" value="7.0.0.67-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>7.0.0.66-SNAPSHOT</version>
<version>7.0.0.67-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
3 changes: 0 additions & 3 deletions test/XmlElemNew.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
xmlelem = XmlElemNew(xml_document,"Lucee");
expect(isxmldoc(xml_document)).toBeTrue();
expect(IsXmlElem(xmlelem)).toBeTrue();


// SystemOutput(createObject("java","lucee.transformer.dynamic.DynamicInvoker").observeData(),1,1);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/a_debug_build/_MongoDB.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="mongodb" {
if (!isempty(variables.mongoDB.user) && !isEmpty(variables.mongoDB.pass))
uri = "mongodb://#variables.mongoDB.user#:#variables.mongoDB.pass#@#variables.mongoDB.server#:#variables.mongoDB.port#";

systemOutput("MongoDB URI: " & uri, true, true);
// systemOutput("MongoDB URI: " & uri, true, true);

// test host/port via http, should return: "It looks like you are trying to access MongoDB over HTTP on the native driver port."
/*
Expand Down
5 changes: 2 additions & 3 deletions test/components/Administrator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
describe( title="test application listener functions", skip=true, body=function() {
beforeEach(function( currentSpec ){
getApplicationListener = adminWeb.getApplicationListener();
systemOutput("getApplicationListener: #getApplicationListener.toJson()#", true);
// systemOutput("getApplicationListener: #getApplicationListener.toJson()#", true);
assertEquals(isStruct(getApplicationListener), true);
});

Expand Down Expand Up @@ -1857,8 +1857,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
updateAvailable=deserializeJson(http.filecontent);

if (arrayIsEmpty(updateAvailable.otherVersions)){

systemOutput("WARNING: updateAvailable.otherVersions is empty", true, true);
// systemOutput("WARNING: updateAvailable.otherVersions is empty", true, true);
}
else {

Expand Down
8 changes: 4 additions & 4 deletions test/extension/S3.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
describe( title="Test the S3 extension", body=function() {

it(title="create/delete a empty bucket", skip=isNotSupported(), body=function( currentSpec ){
SystemOutput(root,1,1);
// SystemOutput(root,1,1);
var bucketName = "#id#-bucket-1";
var bucketPath=root&bucketName;
try {
Expand Down Expand Up @@ -118,7 +118,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
});

it(title="copy a empty bucket", skip=isNotSupported(), body=function( currentSpec ){
SystemOutput(root,1,1);
// SystemOutput(root,1,1);
var bucketName = "#id#-copy1";
var bucketPathSrc=root&bucketName;
var bucketPathTrg=bucketPathSrc&"copied";
Expand Down Expand Up @@ -150,7 +150,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {


it(title="copy a bucket with content", skip=isNotSupported(), body=function( currentSpec ){
SystemOutput(root,1,1);
// SystemOutput(root,1,1);
var bucketName = "#id#-copy2";
var bucketPathSrc=root&bucketName;
var folderPathSrc=bucketPathSrc&"/folder1";
Expand Down Expand Up @@ -231,7 +231,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
});

xit(title="move a bucket with content", skip=isNotSupported(), body=function( currentSpec ){
SystemOutput(root,1,1);
// SystemOutput(root,1,1);
var bucketName = "#id#-copy-move";
var bucketPathSrc=root&bucketName;
var folderPathSrc=bucketPathSrc&"/folder1";
Expand Down
2 changes: 1 addition & 1 deletion test/extension/S3_application/index.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
try {
DirectoryExists( s3Url );
} catch ( e ) {
SystemOutput( "Testing VFS s3 profile: [#s3Url#]", true );
// SystemOutput( "Testing VFS s3 profile: [#s3Url#]", true );
rethrow;
}
</cfscript>
6 changes: 3 additions & 3 deletions test/functions/BitOr.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it("should correctly perform bitwise OR between two large String values", function() {
systemOutput("------", true);
// systemOutput("------", true);
application action="update" preciseMath=true;
systemOutput(getApplicationSettings().preciseMath, true);
// systemOutput(getApplicationSettings().preciseMath, true);
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("18446744073709551615");
application action="update" preciseMath=false;
systemOutput(getApplicationSettings().preciseMath, true);
// systemOutput(getApplicationSettings().preciseMath, true);
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("9223372036854775807");
});
it("should correctly perform bitwise OR between two large Number values", function() {
Expand Down
24 changes: 12 additions & 12 deletions test/functions/FileSetAccessMode.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop array=st index="local.item"{
systemOutput( item, true );
}
// loop array=st index="local.item"{
// systemOutput( item, true );
// }

arrayAppend( tests, _file( dir, "644.txt", "644" ) );
arrayAppend( tests, _file( dir, "743.txt", "743" ) );
Expand All @@ -37,18 +37,18 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
var files = directoryList( dir, true, "query");
var st = QueryToStruct( files, "name" );

loop collection=st item="local.item"{
systemOutput( item, true );
}
loop array=tests item="local.test" {
systemOutput( test, true );
}
// loop collection=st item="local.item"{
// systemOutput( item, true );
// }
// loop array=tests item="local.test" {
// systemOutput( test, true );
// }
loop array=tests item="local.test" {
systemOutput( test, true );
// systemOutput( test, true );
var key = mid( test.name, len( dir ) + 1 );
systemOutput( key, true );
// systemOutput( key, true );
expect( st ).toHaveKey( key );
systemOutput( st[ key ], true );
// systemOutput( st[ key ], true );
expect( test.mode ).toBe( st[ key ].mode );
}

Expand Down
2 changes: 1 addition & 1 deletion test/functions/GetMetaData.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {

assertEquals("ordered,type", listSort( meta.keyList(), "text" ) );
assertEquals("unordered",meta.ordered);
assertEquals("regular",meta.type);
//assertEquals("regular",meta.type);
});

it( title = 'Checking ordered struct', body = function( currentSpec ) {
Expand Down
6 changes: 3 additions & 3 deletions test/functions/IsJson.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
var canJson5 = ( len( getFunctionData( "isJson" ).arguments ) == 2 );

expect( ArrayLen( json5Tests ) ).toBeGT( 0 );
systemOutput( "", true);
systemOutput( "running json5 testsuite with #ArrayLen( json5Tests )# tests", true);
// systemOutput( "", true);
// systemOutput( "running json5 testsuite with #ArrayLen( json5Tests )# tests", true);

loop array=json5Tests item="local.test"{
var fileType = listLast( test, "." );
Expand All @@ -143,7 +143,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
}
// due to false positives, this function is private / disabled LDEV-5017
if ( isJson( fileRead( test ) ) neq expectedResult ) {
systemOutput( "expected: " & expectedResult & " isJson:" & isJson( fileRead( test ) ) & " " & test, true);
// systemOutput( "expected: " & expectedResult & " isJson:" & isJson( fileRead( test ) ) & " " & test, true);
}
//TBD add second argument, version for json5 support
//expect( isJson( fileRead( test ) ) ).toBe( expectedResult, test );
Expand Down
33 changes: 33 additions & 0 deletions test/functions/LSParseNumber.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {
function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" precisemath=variables.preciseMath;
};

function run( testResults, testBox ){
describe( "Test LSParseNumber", function(){

it( "Test with Large number", function(){
var n = "2.305.843.009,01";
var locale = "german (standard)";
application action="update" preciseMath=false;
expect( LSParseNumber( n, locale ) ).toBe( 2305843009.01 );
application action="update" preciseMath=true;
expect( LSparseNumber( n, locale ) ).toBe( 2305843009.01 ); // but it returns 2305843009.01 ?
});

it( "Test with Large number", function(){
var n = "2.305.843.009.213.693.951,01";
var locale = "german (standard)";
application action="update" preciseMath=false;
expect( LSParseNumber( n, locale ) ).toBe( 2305843009213693952 );
application action="update" preciseMath=true;
expect( LSparseNumber( n, locale ) ).toBe( 2305843009213693951.01 ); // LSParseNumber doesn't support big numbers
});

} );
}
}
Loading

0 comments on commit 34c5100

Please sign in to comment.