-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/org/htmlunit/javascript/preprocessor/HtmxOneNineTenScriptPreprozessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2002-2024 Gargoyle Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.htmlunit.javascript.preprocessor; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.htmlunit.ScriptPreProcessor; | ||
import org.htmlunit.html.HtmlElement; | ||
import org.htmlunit.html.HtmlPage; | ||
|
||
/** | ||
* Preprozessor to fix one default parameter method. | ||
* | ||
* @author Ronald Brill | ||
*/ | ||
public class HtmxOneNineTenScriptPreprozessor implements ScriptPreProcessor { | ||
|
||
private final ScriptPreProcessor nextScriptPreProcessor_; | ||
|
||
public HtmxOneNineTenScriptPreprozessor() { | ||
nextScriptPreProcessor_ = null; | ||
} | ||
|
||
public HtmxOneNineTenScriptPreprozessor(final ScriptPreProcessor nextScriptPreProcessor) { | ||
nextScriptPreProcessor_ = nextScriptPreProcessor; | ||
} | ||
|
||
@Override | ||
public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName, | ||
final int lineNumber, final HtmlElement htmlElement) { | ||
|
||
String patchedSourceCode = sourceCode; | ||
|
||
if (sourceName.contains("/htmx.js")) { | ||
patchedSourceCode = StringUtils.replace( | ||
sourceCode, | ||
"function makeTagRegEx(tag, global = false) {", | ||
"function makeTagRegEx(tag) {\n" | ||
+ " " | ||
+ "var global = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n"); | ||
} | ||
else if (sourceName.contains("/htmx.min.js")) { | ||
patchedSourceCode = StringUtils.replace( | ||
sourceCode, | ||
"function e(e,t=false){", | ||
"function e(e){" | ||
+ "var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; "); | ||
} | ||
|
||
if (nextScriptPreProcessor_ != null) { | ||
return nextScriptPreProcessor_.preProcess(htmlPage, patchedSourceCode, sourceName, lineNumber, htmlElement); | ||
} | ||
|
||
return patchedSourceCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2002-2024 Gargoyle Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.htmlunit.libraries; | ||
|
||
import org.htmlunit.WebClient; | ||
import org.htmlunit.javascript.preprocessor.HtmxOneNineTenScriptPreprozessor; | ||
import org.htmlunit.junit.BrowserRunner; | ||
import org.htmlunit.junit.BrowserRunner.Alerts; | ||
import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Tests for <a href="https://htmx.org/">htmx</a>. | ||
* | ||
* @author Ronald Brill | ||
*/ | ||
@RunWith(BrowserRunner.class) | ||
public class HtmxTest1x9x10 extends HtmxTest { | ||
|
||
/** | ||
* @throws Exception if an error occurs | ||
*/ | ||
@Test | ||
@Alerts(DEFAULT = "passes:679failures:1", | ||
FF = "passes:679failures:0", | ||
FF_ESR = "passes:679failures:0", | ||
IE = "not testable") | ||
@HtmlUnitNYI( | ||
CHROME = "passes:679failures:0", | ||
EDGE = "passes:679failures:0") | ||
public void htmx() throws Exception { | ||
// the test page runs in an endless loop in ie | ||
if (getBrowserVersion().isIE()) { | ||
return; | ||
} | ||
htmx("htmx-1.9.10"); | ||
} | ||
|
||
@Override | ||
protected void setupWebClient(final WebClient webClient) { | ||
super.setupWebClient(webClient); | ||
|
||
webClient.setScriptPreProcessor(new HtmxOneNineTenScriptPreprozessor()); | ||
webClient.getOptions().setThrowExceptionOnScriptError(false); | ||
} | ||
} |