mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
strip dashes from uuids before handling them
This commit is contained in:
parent
e44ebda56f
commit
9cb32a843f
@ -7,8 +7,8 @@ var skins = require("./skins");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
// 0098cb60-fa8e-427c-b299-793cbd302c9a
|
||||
var valid_user_id = /^[0-9a-fA-F\-]{32,36}$/; // uuid
|
||||
// 0098cb60fa8e427cb299793cbd302c9a
|
||||
var valid_user_id = /^[0-9a-fA-F]{32}$/; // uuid
|
||||
var hash_pattern = /[0-9a-f]+$/;
|
||||
|
||||
// gets the hash from the textures.minecraft.net +url+
|
||||
|
||||
@ -67,6 +67,9 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
// Prevent app from crashing/freezing
|
||||
if (size < config.avatars.min_size || size > config.avatars.max_size) {
|
||||
// "Unprocessable Entity", valid request, but semantically erroneous:
|
||||
@ -84,9 +87,6 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
try {
|
||||
helpers.get_avatar(req.id, userId, overlay, size, function(err, status, image, hash) {
|
||||
if (err) {
|
||||
|
||||
@ -17,6 +17,8 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
if (!helpers.id_valid(userId)) {
|
||||
callback({
|
||||
status: -2,
|
||||
@ -25,9 +27,6 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
try {
|
||||
helpers.get_cape(rid, userId, function(err, hash, status, image) {
|
||||
if (err) {
|
||||
|
||||
@ -85,6 +85,9 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
if (scale < config.renders.min_scale || scale > config.renders.max_scale) {
|
||||
callback({
|
||||
status: -2,
|
||||
@ -99,9 +102,6 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
try {
|
||||
helpers.get_render(rid, userId, scale, overlay, body, function(err, status, hash, image) {
|
||||
if (err) {
|
||||
|
||||
@ -75,6 +75,8 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
if (!helpers.id_valid(userId)) {
|
||||
callback({
|
||||
status: -2,
|
||||
@ -83,9 +85,6 @@ module.exports = function(req, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
userId = userId.replace(/-/g, "");
|
||||
|
||||
try {
|
||||
helpers.get_skin(rid, userId, function(err, hash, status, image, slim) {
|
||||
if (err) {
|
||||
|
||||
@ -88,8 +88,8 @@ describe("Crafatar", function() {
|
||||
assert.strictEqual(helpers.id_valid("1DCEF164FF0A47F2B9A691385C774EE7"), true);
|
||||
done();
|
||||
});
|
||||
it("dashed uuid is valid", function(done) {
|
||||
assert.strictEqual(helpers.id_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), true);
|
||||
it("dashed uuid is not valid", function(done) {
|
||||
assert.strictEqual(helpers.id_valid("0098cb60-fa8e-427c-b299-793cbd302c9a"), false);
|
||||
done();
|
||||
});
|
||||
it("username is invalid", function(done) {
|
||||
@ -300,6 +300,10 @@ describe("Crafatar", function() {
|
||||
url: "http://localhost:3000/avatars/853c80ef3c3749fdaa49938b674adae6?size=16",
|
||||
crc32: [4264176600],
|
||||
},
|
||||
"avatar with existing dashed uuid": {
|
||||
url: "http://localhost:3000/avatars/853c80ef-3c37-49fd-aa49938b674adae6?size=16",
|
||||
crc32: [4264176600],
|
||||
},
|
||||
"avatar with non-existent uuid": {
|
||||
url: "http://localhost:3000/avatars/00000000000000000000000000000000?size=16",
|
||||
crc32: [3348154329],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user