Lädt...

🔧 CodeSOD: An Alerting Validation


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: thedailywtf.com

There are things which are true. Regular expressions frequently perform badly. They're hard to read. Email addresses are not actually regular languages, and thus can't truly be validated (in all they're many possible forms) by a pure regex.

These are true. It's also true that a simple regex can get you most of the way there.

Lucas found this in their codebase, for validating emails.

function echeck(str) {

    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    if (str.indexOf(" ")!=-1){
        alert("You must include an accurate email address for a response.");
        return false;
    }

    return true;
}

It checks that the string contains an "@", and the "@" is not at the beginning or end of the string. Then it does the same check for a ".". Then it checks that there isn't a second "@". Then it checks that there are at least two non-"@" characters before the ".". Then it checks that there's at least one "." after the "@". Then it checks that there are no spaces.

Like a regex, I don't think this covers the entire space of valid and invalid email addresses, but that's just because the email address spec is complicated. It likely qualifies as "good enough", on that front. But it's the most awkward way to express that series of tests, especially since they create variables which might be useful, but never use them, thus calling str.indexOf many, many times. The awkwardness becomes more obvious with the way it outputs the same error message in multiple branches. Outputs them using alert I might add, which is the kind of choice that should send someone to the Special Hell™.

[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
...

🔧 CodeSOD: An Alerting Validation


📈 38.59 Punkte
🔧 Programmierung

🔧 CodeSOD: Where is the Validation At?


📈 19.34 Punkte
🔧 Programmierung

🔧 CodeSOD: Input Validation is a Sure Thing


📈 19.34 Punkte
🔧 Programmierung

🔧 Monitoring What Matters: Practical Alerting for Scalable Systems


📈 19.25 Punkte
🔧 Programmierung

🔧 Building a Scalable Notifications and Alerting System 🔥🚀


📈 19.25 Punkte
🔧 Programmierung

🔧 How to develop your service health alerting strategy


📈 19.25 Punkte
🔧 Programmierung

🔧 Implementing monitoring and alerting for distributed system - Part 6


📈 19.25 Punkte
🔧 Programmierung

🔧 Current problems in the alerting space


📈 19.25 Punkte
🔧 Programmierung

📰 Real-time Vulnerability Alerting


📈 19.25 Punkte
📰 IT Security Nachrichten

🔧 PMM V2.33: Offline Metric Collection, Guided Alerting Tour, Security Fixes, and More!


📈 19.25 Punkte
🔧 Programmierung

🐧 Add GeoIP alerting to your SSH logins


📈 19.25 Punkte
🐧 Linux Tipps

📰 Real-time Vulnerability Alerting


📈 19.25 Punkte
📰 IT Security Nachrichten

📰 (g+) Alerting und Monitoring mit Prometheus: "Firing HostDown on 10.138.250.3:9100"


📈 19.25 Punkte
📰 IT Nachrichten

📰 Apple Is Alerting iPhone Users of Spyware Attacks


📈 19.25 Punkte
📰 IT Security Nachrichten

🔧 Attaching a Percona Monitoring and Management Graph Image Along with an Alerting Notification


📈 19.25 Punkte
🔧 Programmierung

🔧 Critical Test Based Alerting with PagerDuty and Testkube


📈 19.25 Punkte
🔧 Programmierung

🐧 sampler: a tool for shell commands execution, visualization and alerting


📈 19.25 Punkte
🐧 Linux Tipps

🔧 AIOps Powered by AWS: Developing Intelligent Alerting with CloudWatch & Built-In Capabilities


📈 19.25 Punkte
🔧 Programmierung

🔧 Getting Started with Prometheus Alerting


📈 19.25 Punkte
🔧 Programmierung

🔧 AIOps Powered by AWS: Developing Intelligent Alerting with CloudWatch & Built-In Capabilities


📈 19.25 Punkte
🔧 Programmierung

📰 Grafana 8.0 integrates with Prometheus alerting


📈 19.25 Punkte
📰 IT Nachrichten

📰 How to Achieve the Best Risk-Based Alerting (Bye-Bye SIEM)


📈 19.25 Punkte
📰 IT Security Nachrichten

📰 Everbridge integriert seine Lösung <b>IT</b> Alerting in QRadar von IBM


📈 19.25 Punkte
📰 IT Security Nachrichten

🍏 Why Apple’s approach to alerting victims of spyware attacks is the right one


📈 19.25 Punkte
🍏 iOS / Mac OS

🕵️ Open Distro for Elasticsearch up to 1.13.0.x Alerting Plugin server-side request forgery


📈 19.25 Punkte
🕵️ Sicherheitslücken

🔧 Bringing context to alerting and incident management


📈 19.25 Punkte
🔧 Programmierung

matomo