Giter Club home page Giter Club logo

Comments (1)

eyalroz avatar eyalroz commented on September 8, 2024

I'm not offering a PR this time (probably), but here is a bit of code:

bool tag_name_is_valid(const char* restrict str, size_t len)
{
	// Rules as appear here:
	// https://stackoverflow.com/a/26382358/1593077

	// rule 1
	if (str[0] == '.') { return false; }
	if (strstr(str, "/.")) { return false; }
	if (strstr(str, ".lock/")) { return false; }
	if (strcmp(str + len - 5, ".lock") == 0) { return false; }
	// rule 2 - unused, since theoretically we could have "allow-onelevel"
	// if (strchr(str, '/') == NULL) { return false; }
	// rule 3
	if (strstr(str, "..")) { return false; }
	// rule 4
	for(size_t i; i < len; i++) {
		char c = str[i];
		bool is_ascii_control_char = (c < 0x20) || (c == 0x7F /* DEL */);
		if (is_ascii_control_char || c == ' ' || c == '~' || c == '^' || c ==':' ) return false;
	}
	// rule 4
	if ( (strpbrk(str, "?*[") != NULL) ) { return false; }
	// rule 5
	if ( (strpbrk(str, "?*[") != NULL) ) { return false; }
	// rule 6
	if ( (str[0]) || (str[len - 1] == '/') || (strstr(str, "//") != NULL) ) { return false; }
	// rule 7
	if (str[len - 1] == '.') { return false; }
	// rule 8
	if (strchr(str,"@{") != NULL) { return false; }
	// rule 9
	if (str[0] == '@' && len == 1) { return false; }
	// rule 10
	if (strchr(str, '\\') != NULL) { return false; }
	return true;
}

from crap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.