Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix php7.3 regexp hyphen #37

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions device_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function exist($id) {

public function exists_name($userid, $name) {
$userid = intval($userid);
$name = preg_replace('/[^\p{L}_\p{N}\s-:]/u','',$name);
$name = preg_replace('/[^\p{L}_\p{N}\s\-:]/u','',$name);

$stmt = $this->mysqli->prepare("SELECT id FROM device WHERE userid=? AND name=?");
$stmt->bind_param("is", $userid, $name);
Expand All @@ -128,7 +128,7 @@ public function exists_name($userid, $name) {

public function exists_nodeid($userid, $nodeid) {
$userid = intval($userid);
$nodeid = preg_replace('/[^\p{L}_\p{N}\s-:]/u','',$nodeid);
$nodeid = preg_replace('/[^\p{L}_\p{N}\s\-:]/u','',$nodeid);

$stmt = $this->mysqli->prepare("SELECT id FROM device WHERE userid=? AND nodeid=?");
$stmt->bind_param("is", $userid, $nodeid);
Expand Down Expand Up @@ -303,9 +303,9 @@ private function load_device_to_redis($id) {
public function autocreate($userid, $_nodeid, $_type) {
$userid = intval($userid);

$nodeid = preg_replace('/[^\p{L}_\p{N}\s-:]/u','',$_nodeid);
$nodeid = preg_replace('/[^\p{L}_\p{N}\s\-:]/u','',$_nodeid);
if ($_nodeid != $nodeid) return array("success"=>false, "message"=>"Invalid nodeid");
$type = preg_replace('/[^\/\|\,\w\s-:]/','',$_type);
$type = preg_replace('/[^\/\|\,\w\s\-:]/','',$_type);
if ($_type != $type) return array("success"=>false, "message"=>"Invalid type");

$name = "$nodeid:$type";
Expand All @@ -328,22 +328,22 @@ public function autocreate($userid, $_nodeid, $_type) {

public function create($userid, $nodeid, $name, $description, $type) {
$userid = intval($userid);
$nodeid = preg_replace('/[^\p{L}_\p{N}\s-:]/u', '', $nodeid);
$nodeid = preg_replace('/[^\p{L}_\p{N}\s\-:]/u', '', $nodeid);

if (isset($name)) {
$name = preg_replace('/[^\p{L}_\p{N}\s-:]/u', '', $name);
$name = preg_replace('/[^\p{L}_\p{N}\s\-:]/u', '', $name);
} else {
$name = $nodeid;
}

if (isset($description)) {
$description = preg_replace('/[^\p{L}_\p{N}\s-:]/u', '', $description);
$description = preg_replace('/[^\p{L}_\p{N}\s\-:]/u', '', $description);
} else {
$description = '';
}

if (isset($type) && $type != 'null') {
$type = preg_replace('/[^\/\|\,\w\s-:]/','', $type);
$type = preg_replace('/[^\/\|\,\w\s\-:]/','', $type);
} else {
$type = '';
}
Expand Down Expand Up @@ -413,7 +413,7 @@ public function set_fields($id, $fields) {
$fields = json_decode(stripslashes($fields));

if (isset($fields->name)) {
if (preg_replace('/[^\p{N}\p{L}_\s-:]/u','',$fields->name)!=$fields->name) return array('success'=>false, 'message'=>'invalid characters in device name');
if (preg_replace('/[^\p{N}\p{L}_\s\-:]/u','',$fields->name)!=$fields->name) return array('success'=>false, 'message'=>'invalid characters in device name');
$stmt = $this->mysqli->prepare("UPDATE device SET name = ? WHERE id = ?");
$stmt->bind_param("si",$fields->name,$id);
if ($stmt->execute()) {
Expand All @@ -423,7 +423,7 @@ public function set_fields($id, $fields) {
}

if (isset($fields->description)) {
if (preg_replace('/[^\p{N}\p{L}_\s-:]/u','',$fields->description)!=$fields->description) return array('success'=>false, 'message'=>'invalid characters in device description');
if (preg_replace('/[^\p{N}\p{L}_\s\-:]/u','',$fields->description)!=$fields->description) return array('success'=>false, 'message'=>'invalid characters in device description');
$stmt = $this->mysqli->prepare("UPDATE device SET description = ? WHERE id = ?");
$stmt->bind_param("si",$fields->description,$id);
if ($stmt->execute()) {
Expand All @@ -433,7 +433,7 @@ public function set_fields($id, $fields) {
}

if (isset($fields->nodeid)) {
if (preg_replace('/[^\p{N}\p{L}_\s-:]/u','',$fields->nodeid)!=$fields->nodeid) return array('success'=>false, 'message'=>'invalid characters in device nodeid');
if (preg_replace('/[^\p{N}\p{L}_\s\-:]/u','',$fields->nodeid)!=$fields->nodeid) return array('success'=>false, 'message'=>'invalid characters in device nodeid');
$stmt = $this->mysqli->prepare("UPDATE device SET nodeid = ? WHERE id = ?");
$stmt->bind_param("si",$fields->nodeid,$id);
if ($stmt->execute()) {
Expand All @@ -443,7 +443,7 @@ public function set_fields($id, $fields) {
}

if (isset($fields->type)) {
if (preg_replace('/[^\/\|\,\w\s-:]/','',$fields->type)!=$fields->type) return array('success'=>false, 'message'=>'invalid characters in device type');
if (preg_replace('/[^\/\|\,\w\s\-:]/','',$fields->type)!=$fields->type) return array('success'=>false, 'message'=>'invalid characters in device type');
$stmt = $this->mysqli->prepare("UPDATE device SET type = ? WHERE id = ?");
$stmt->bind_param("si",$fields->type,$id);
if ($stmt->execute()) {
Expand Down
2 changes: 1 addition & 1 deletion device_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function load_template_list() {
}

public function get_template($type) {
$type = preg_replace('/[^\p{L}_\p{N}\s-:]/u','', $type);
$type = preg_replace('/[^\p{L}_\p{N}\s\-:]/u','', $type);
$result = $this->load_template_list();
if (isset($result['success']) && $result['success'] == false) {
return $result;
Expand Down