{"ScriptPreparationCode":"var url1 = \u0022https://localhost:3000/test?key1=value1\u0026key2=value2#test\u0022;\r\n\r\nconst urlPattern = /^(https?:\\/\\/[^\\/?#]\u002B[^?#]*)?(?:\\?([^#]*))?(?:#([^?]*))?(?:\\?([^#]*))?/;\r\n\r\nfunction extractParts1(inputUrl) {\r\n const match = inputUrl.match(urlPattern);\r\n if (!match) return null;\r\n\r\n let url = match[1] || null;\r\n let searchParams = match[2] || null;\r\n let fragment = match[3] || null;\r\n // If there are query parameters after the fragment\r\n if (match[4]) {\r\n searchParams = searchParams ? searchParams \u002B \u0027\u0026\u0027 \u002B match[4] : match[4];\r\n }\r\n\r\n return {\r\n url,\r\n searchParams,\r\n fragment\r\n };\r\n}\r\n\r\n\r\nfunction extractParts2(inputUrl) {\r\n // Parse basic URL and fragment\r\n const [base, fragmentQuery] = inputUrl.split(\u0027#\u0027);\r\n \r\n // Parse URL and search parameters from base\r\n let [url, searchParams] = base.split(\u0027?\u0027);\r\n\r\n // If there\u0027s fragment data, check for additional query parameters\r\n let fragment = null;\r\n let extraSearchParams = null;\r\n if (fragmentQuery) {\r\n if (fragmentQuery.includes(\u0027?\u0027)) {\r\n [fragment, extraSearchParams] = fragmentQuery.split(\u0027?\u0027);\r\n searchParams = searchParams ? \u0060${searchParams}\u0026${extraSearchParams}\u0060 : extraSearchParams;\r\n } else {\r\n fragment = fragmentQuery;\r\n }\r\n }\r\n\r\n return {\r\n url,\r\n searchParams: searchParams || null,\r\n fragment: fragment || null\r\n };\r\n}\r\n\r\n\r\nfunction extractParts3(inputUrl) {\r\n const queryIndex = inputUrl.indexOf(\u0027?\u0027);\r\n const hashIndex = inputUrl.indexOf(\u0027#\u0027);\r\n\r\n const hasQueryBeforeHash = queryIndex !== -1 \u0026\u0026 (hashIndex === -1 || queryIndex \u003C hashIndex);\r\n\r\n const url = hasQueryBeforeHash ? inputUrl.substring(0, queryIndex) : (hashIndex !== -1 ? inputUrl.substring(0, hashIndex) : inputUrl);\r\n\r\n let searchParams = null, fragment = null;\r\n\r\n if (hashIndex !== -1) {\r\n const fragmentWithQuery = inputUrl.substring(hashIndex \u002B 1);\r\n const fragmentQueryIndex = fragmentWithQuery.indexOf(\u0027?\u0027);\r\n\r\n if (fragmentQueryIndex !== -1) {\r\n fragment = fragmentWithQuery.substring(0, fragmentQueryIndex);\r\n searchParams = fragmentWithQuery.substring(fragmentQueryIndex \u002B 1);\r\n if (hasQueryBeforeHash) {\r\n searchParams = inputUrl.substring(queryIndex \u002B 1, hashIndex) \u002B \u0027\u0026\u0027 \u002B searchParams;\r\n }\r\n } else {\r\n fragment = fragmentWithQuery;\r\n }\r\n }\r\n\r\n if (hasQueryBeforeHash \u0026\u0026 !searchParams) {\r\n searchParams = hashIndex !== -1 ? inputUrl.substring(queryIndex \u002B 1, hashIndex) : inputUrl.substring(queryIndex \u002B 1);\r\n }\r\n\r\n return {\r\n url,\r\n searchParams: searchParams || null,\r\n fragment: fragment || null\r\n };\r\n}\r\n\r\nfunction extractParts4(inputUrl) {\r\n const searchParamsIndex = inputUrl.indexOf(\u0027?\u0027);\r\n const fragmentIndex = inputUrl.indexOf(\u0027#\u0027);\r\n \r\n // \u6761\u4EF6\u8A55\u4FA1\u306E\u7D50\u679C\u3092\u5909\u6570\u306B\u683C\u7D0D\r\n const hasSearchParams = searchParamsIndex !== -1;\r\n const hasFragment = fragmentIndex !== -1;\r\n const hasSearchParamsBeforeFragment = hasSearchParams \u0026\u0026 (!hasFragment || searchParamsIndex \u003C fragmentIndex);\r\n\r\n let endOfUrlIndex = inputUrl.length;\r\n if (hasSearchParamsBeforeFragment) {\r\n endOfUrlIndex = searchParamsIndex;\r\n } else if (hasFragment) {\r\n endOfUrlIndex = fragmentIndex;\r\n }\r\n \r\n const url = inputUrl.substring(0, endOfUrlIndex);\r\n \r\n let searchParams = null;\r\n let fragmentText = null;\r\n\r\n if (hasFragment) {\r\n const fragmentWithQuery = inputUrl.substring(fragmentIndex \u002B 1);\r\n const insideFragmentIndex = fragmentWithQuery.indexOf(\u0027?\u0027);\r\n const hasInsideFragment = insideFragmentIndex !== -1;\r\n\r\n fragmentText = hasInsideFragment \r\n ? fragmentWithQuery.substring(0, insideFragmentIndex)\r\n : fragmentWithQuery;\r\n\r\n if (hasInsideFragment) {\r\n const fragmentSearchParams = fragmentWithQuery.substring(insideFragmentIndex \u002B 1);\r\n searchParams = hasSearchParamsBeforeFragment\r\n ? inputUrl.substring(searchParamsIndex \u002B 1, fragmentIndex) \u002B \u0027\u0026\u0027 \u002B fragmentSearchParams\r\n : fragmentSearchParams;\r\n }\r\n }\r\n\r\n if (hasSearchParamsBeforeFragment \u0026\u0026 !searchParams) {\r\n searchParams = hasFragment \r\n ? inputUrl.substring(searchParamsIndex \u002B 1, fragmentIndex)\r\n : inputUrl.substring(searchParamsIndex \u002B 1);\r\n }\r\n\r\n return {\r\n url,\r\n searchParams: searchParams || null,\r\n fragment: fragmentText || null\r\n };\r\n}\r\n\r\nfunction extractParts5(inputUrl) {\r\n return new URL(inputUrl);\r\n}","TestCases":[{"Name":"patern 1","Code":"extractParts1(url1);","IsDeferred":false},{"Name":"patern 2","Code":"extractParts2(url1);","IsDeferred":false},{"Name":"patern 3","Code":"extractParts3(url1);","IsDeferred":false},{"Name":"patern 4","Code":"extractParts4(url1);","IsDeferred":false},{"Name":"pattern 5","Code":"extractParts5(url1);","IsDeferred":false}]}