<commit_before><?php

$app->get('/todos', 'APIrequest', function () use ($app){

	$todos = R::findAll('todo');
	$app->render(200, ['todos'=>R::exportAll($todos)]);

});

$app->post('/todos/new', 'APIrequest', function () use ($app){

	$todo = R::dispense('todo');
	$todo->done = false;
	$todo->text = preg_replace('/<(:?script|style)\b[^>]*>(.*?)<\/(:?script|style)>/is', "$1", $app->request()->post('text'));
	R::store($todo);

	$app->render(200, ['todo'=>$todo->export()]);
});

$app->post('/todos/update/:id', 'APIrequest', function ($id) use ($app){

	$todo  = R::findOne('todo', ' id = ?', [$id]);

	if($todo){

		if($app->request()->post('text')){
			$todo->text = preg_replace('/<(:?script|style)\b[^>]*>(.*?)<\/(:?script|style)>/is', "$1", $app->request()->post('text'));
		}
		if($app->request()->post('done')){
			$todo->done = ($app->request()->post('done')=='true');
		}

		R::store($todo);

		$app->render(200, ['todo'=>$todo->export()]);

	}else{
		$app->render(404, ['error'=>'To-Do not found.']);
	}
});

$app->post('/todos/delete/:id', 'APIrequest', function ($id) use ($app){

	$todo  = R::findOne('todo', ' id = ?', [$id]);

	if($todo){
		R::trash($todo);
		$app->render(200, ['deleted'=>true]);
	}else{
		$app->render(404, ['error'=>'To-Do not found.']);
	}
});<commit_msg>mejor con htmlspecialchars()<commit_after><?php

$app->get('/todos', 'APIrequest', function () use ($app){

	$todos = R::findAll('todo');
	$app->render(200, ['todos'=>R::exportAll($todos)]);

});

$app->post('/todos/new', 'APIrequest', function () use ($app){

	$todo = R::dispense('todo');
	$todo->done = false;
	$todo->text = htmlspecialchars($app->request()->post('text'));
	R::store($todo);

	$app->render(200, ['todo'=>$todo->export()]);
});

$app->post('/todos/update/:id', 'APIrequest', function ($id) use ($app){

	$todo  = R::findOne('todo', ' id = ?', [$id]);

	if($todo){

		if($app->request()->post('text')){
			$todo->text = htmlspecialchars($app->request()->post('text'));
		}
		if($app->request()->post('done')){
			$todo->done = ($app->request()->post('done')=='true');
		}

		R::store($todo);

		$app->render(200, ['todo'=>$todo->export()]);

	}else{
		$app->render(404, ['error'=>'To-Do not found.']);
	}
});

$app->post('/todos/delete/:id', 'APIrequest', function ($id) use ($app){

	$todo  = R::findOne('todo', ' id = ?', [$id]);

	if($todo){
		R::trash($todo);
		$app->render(200, ['deleted'=>true]);
	}else{
		$app->render(404, ['error'=>'To-Do not found.']);
	}
});
{'fraction_non_alphanumeric': 0.3313180169286578, 'fraction_numerical': 0.015316404675534058, 'mean_word_length': 5.251889168765743, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7346463', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1010, 'n_words': 142}