Adding RegEx input checks and removing license #40

Merged
SinusFox merged 38 commits from adding-results-and-export into main 2024-10-07 15:48:15 +00:00
6 changed files with 58 additions and 29 deletions
-21
View File
@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 Marcel Pöppe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+2 -1
View File
@@ -47,7 +47,8 @@ ToDo
4. Push your branch: `git push origin featurename` 4. Push your branch: `git push origin featurename`
5. Create a pull request 5. Create a pull request
# Licence # Licence
This project is licensed under the [MIT License](https://github.com/Spaceholder-Programming/Operations-Research-Tool?tab=MIT-1-ov-file). For further information, please check out the [LICENSE](https://github.com/Spaceholder-Programming/Operations-Research-Tool/blob/main/LICENCE.txt).
=======
# Contact # Contact
If you have the desire to contact the team behind this project, use the contact details on our GitHub accounts: If you have the desire to contact the team behind this project, use the contact details on our GitHub accounts:
+ [bRNS98](https://github.com/bRNS98) + [bRNS98](https://github.com/bRNS98)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

+2 -2
View File
@@ -15,8 +15,8 @@ const geistMono = localFont({
}); });
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Create Next App", title: "OR-Tool by Spaceholder Programming",
description: "Generated by create next app", description: "OR-Tool by Spaceholder Programming",
}; };
export default function RootLayout({ export default function RootLayout({
+5 -5
View File
@@ -19,19 +19,19 @@ export default function Home() {
</header> </header>
<Box <Box
title={"Objective"} title={"Objective"}
placeholder={"Objective"} placeholder={"Insert your objective here. One objective is allowed. Use one line for it (no \"return\"!) Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx + y\n-786433 x1 + 655361 x2"}
id="objective"/> id="objective"/>
<Box <Box
title={"Subject"} title={"Subject"}
placeholder={"Subject"} placeholder={"Insert your subject here. One per line (divide by 'return' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\n+1 x + 2 y <= 15\n524321 x14 + 524305 x15 <= 4194303.5"}
id="subject"/> id="subject"/>
<Box <Box
title={"Bounds"} title={"Bounds"}
placeholder={"Bounds"} placeholder={"Insert your bounds here. One per line (divide by 'return' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx >= 0\nx > 0\n0 <= x1 <= 1"}
id="bounds"/> id="bounds"/>
<Box <Box
title={"Variables"} title={"Variables"}
placeholder={"Your Variables here"} placeholder={"List all your variables. One per line (divide by 'return' button). Allowed symbols are a-z, A-Z.\nExample:\nx\ny"}
id="vars" /> id="vars" />
<Button <Button
title={"Calculate"} title={"Calculate"}
@@ -47,7 +47,7 @@ export default function Home() {
<br></br> <br></br>
<Output <Output
id="out" id="out"
text={"Ergebnis"}/> text={"Input a problem and an action button to display output..."}/>
{/* <Popup_Button {/* <Popup_Button
title="Popup" title="Popup"
className="button" className="button"
+49
View File
@@ -46,6 +46,52 @@ function walltimeStart() {
return Date.now(); return Date.now();
} }
function isInputValidRegex(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined): boolean {
customLog("Staring input checks...");
// standard case: input is undefined - invalid
if (obj === undefined || obj === null || subj === undefined || subj === null || bounds === undefined || bounds === null || vars === undefined || vars === null) {
customLog("Error: Function isInputValidRegex received undefined or null input.");
return false;
}
// RegEx check for objective
let regex = /^[ (\n)]*[\+-]? *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)( *[\+-] *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*))*[ (\n)]*$/g;
let isValid = regex.test(obj);
if (!isValid) {
customLog("Error: Invalid or missing character in object box.");
return false;
}
// RegEx check for subject
regex = /^([ (\n)]*[\+-]* *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*( *[\+-] *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)* *((<=?)|(>=?)|=) *[\+-]? *\d+(.\d+)?[ (\n)]*)+$/g;
isValid = regex.test(subj);
if (!isValid) {
customLog("Error: Invalid or missing character in subject box.");
return false;
}
// RegEx check for subject
regex = /[ (\n)]*(([a-zA-Z][a-zA-Z0-9]* *((<=?)|(>=?)|=) *\d(.\d+)?)|((\d(.\d+)?) *<=? *[a-zA-Z][a-zA-Z0-9]* *<= *(\d(.\d+)?)))[ (\n)]*/g;
isValid = regex.test(bounds);
if (!isValid) {
customLog("Error: Invalid or missing character in bounds box.");
return false;
}
// RegEx check for variables
regex = /^ *([a-zA-Z][a-zA-Z0-9]*(\n)* *)+$/g;
isValid = regex.test(vars);
if (!isValid) {
customLog("Error: Invalid or missing character in variables box.");
return false;
}
customLog("All input checks successful.");
customLog("");
return true;
}
function isInputFilled(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined) { function isInputFilled(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined) {
if (obj == "" || obj == null || obj == undefined) { if (obj == "" || obj == null || obj == undefined) {
customLog("Error: Empty input field."); customLog("Error: Empty input field.");
@@ -148,6 +194,9 @@ export function calculate_click() {
// catch error: empty input field(s) // catch error: empty input field(s)
if (!isInputFilled(objective, subject, bounds, variables)) return; if (!isInputFilled(objective, subject, bounds, variables)) return;
// catch error: variables field has invalid characters
if (!isInputValidRegex(objective, subject, bounds, variables)) return;
let wholeText: string = "Maximize\n obj: " + objective let wholeText: string = "Maximize\n obj: " + objective
+ "\nSubject To \n" + subject + "\nSubject To \n" + subject
+ "\nBounds \n" + bounds + "\nBounds \n" + bounds