HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/triad-infosec/wp-content/plugins/the-events-calendar/common/src/Tribe/Utils/JSON.php
<?php


/**
 * Class Tribe__Utils__JSON
 *
 * Provides JSON related utility functions.
 */
class Tribe__Utils__JSON {

	/**
	 * Recursively escapes quotes and JSON relevant chars in a string to avoid json operation errors.
	 *
	 * The method will recursively escape any string found.
	 *
	 * @param array|string $value Either a string to escape or an array of strings to escape.
	 *
	 * @return array|string Either an array of escaped strings or the escaped string.
	 */
	public static function escape_string( $value ) {
		if ( ! ( is_string( $value ) || is_array( $value ) ) ) {
			return $value;
		}
		if ( is_array( $value ) ) {
			$escaped = [];
			foreach ( $value as $key => $subvalue ) {
				$escaped[ $key ] = self::escape_string( $subvalue );
			}

			return $escaped;
		}

		$escapers     = [ "\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c" ];
		$replacements = [ "\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b" ];

		return str_replace( $escapers, $replacements, $value );
	}
}