<commit_before>package rewrite

import (
	"log"
	"net/http"
	"net/url"
	"path"
	"strings"

	"github.com/mholt/caddy/caddyhttp/httpserver"
)

// To attempts rewrite. It attempts to rewrite to first valid path
// or the last path if none of the paths are valid.
// Returns true if rewrite is successful and false otherwise.
func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Replacer) Result {
	tos := strings.Fields(to)

	// try each rewrite paths
	t := ""
	query := ""
	for _, v := range tos {
		t = replacer.Replace(v)
		tparts := strings.Split(t, "?")
		t = path.Clean(tparts[0])

		if len(tparts) > 1 {
			query = tparts[1]
		}

		// add trailing slash for directories, if present
		if strings.HasSuffix(v, "/") && !strings.HasSuffix(t, "/") {
			t += "/"
		}

		// validate file
		if isValidFile(fs, t) {
			break
		}
	}
<commit_msg>replace strings.Split for SplitN<commit_after>package rewrite

import (
	"log"
	"net/http"
	"net/url"
	"path"
	"strings"

	"github.com/mholt/caddy/caddyhttp/httpserver"
)

// To attempts rewrite. It attempts to rewrite to first valid path
// or the last path if none of the paths are valid.
// Returns true if rewrite is successful and false otherwise.
func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Replacer) Result {
	tos := strings.Fields(to)

	// try each rewrite paths
	t := ""
	query := ""
	for _, v := range tos {
		t = replacer.Replace(v)
		tparts := strings.SplitN(t, "?", 2)
		t = path.Clean(tparts[0])

		if len(tparts) > 1 {
			query = tparts[1]
		}

		// add trailing slash for directories, if present
		if strings.HasSuffix(v, "/") && !strings.HasSuffix(t, "/") {
			t += "/"
		}

		// validate file
		if isValidFile(fs, t) {
			break
		}
	}

{'fraction_non_alphanumeric': 0.14310246136233543, 'fraction_numerical': 0.004006868918145392, 'mean_word_length': 3.1226415094339623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7623451', 'n_tokens_mistral': 688, 'n_tokens_neox': 624, 'n_words': 184}