Пример #1
0
// TrimString returns the specified number of characters from the
// specified string
func (viewHelper *ViewHelper) TrimString(s string, length int) string {
	if len(s) <= length {
		return html.UnescapeString(s)
	}

	return html.UnescapeString(s[0:length])
}
Пример #2
0
func fetch(urls []string) Entries {
	var result Entries

	p := gofeed.NewParser()

	for _, url := range urls {
		resp, err := http.Get(url)
		if err != nil {
			log.Error("cannot fetch feed", "url", url, "error", err.Error())
			continue
		}

		feed, err := p.Parse(resp.Body)
		resp.Body.Close()

		if err != nil {
			log.Error("cannot parse feed", "url", url, "error", err.Error())
			continue
		}
		for _, it := range feed.Items {
			result = append(result, &Entry{
				Feed: Feed{
					Title: html.UnescapeString(feed.Title),
					Link:  feed.Link,
				},
				Title:     html.UnescapeString(it.Title),
				Link:      it.Link,
				Published: parseTime(it.Published),
			})
		}
	}
	return result
}
Пример #3
0
func (m *Module) formatEvent(event interface{}) string {
	var msg string
	switch t := event.(type) {
	case anaconda.ApiError:
		msg = fmt.Sprintf("Twitter API error %d: %s", t.StatusCode, t.Decoded.Error())
	case anaconda.StatusDeletionNotice:
		msg = fmt.Sprintf("Tweet %d has been deleted", t.Id)
	case anaconda.DirectMessage:
		msg = fmt.Sprintf("Direct message %d by %s sent to %s: %s", t.Id,
			t.SenderScreenName, t.RecipientScreenName, html.UnescapeString(t.Text))
	case anaconda.Tweet:
		if t.RetweetedStatus != nil && t.User.Id != m.user.Id {
			break
		}

		msg = fmt.Sprintf("Tweet %d by %s: %s", t.Id, t.User.ScreenName,
			html.UnescapeString(t.Text))
	case anaconda.EventTweet:
		if t.Event.Event != "favorite" || t.Source.Id != m.user.Id {
			break
		}

		text := html.UnescapeString(t.TargetObject.Text)
		msg = fmt.Sprintf("%s favorited tweet %d by %s: %s",
			t.Source.ScreenName, t.TargetObject.Id, t.Target.ScreenName, text)
	}

	return msg
}
func main() {
	raw := []string{
		"hello",
		"<i>Hello</i>",
		"alert('hello');",
		"foo & bar",
		`"how are you?" He asked.`,
	}

	log.Println("html.EscapeString")
	for _, s := range raw {
		log.Printf("\t%s -> %s", s, html.EscapeString(s))
	}

	log.Println("html.UnescapeString(html.EscapeString)")
	for _, s := range raw {
		flipped := html.UnescapeString(html.EscapeString(s))
		log.Printf("\t%s -> %s", s, flipped)
	}

	escaped := []string{
		"&#225",
		"&raquo;",
		"&middot;",
		"&lt;i&gt;htllo&lt;/i&gt;",
	}

	log.Println("html.UnescapeString")
	for _, s := range escaped {
		log.Printf("\t%s -> %s", s, html.UnescapeString(s))
	}
}
Пример #5
0
func AddQuestions(db *sql.DB, newQns *stackongo.Questions) error {

	defer UpdateTableTimes(db, "questions")
	for _, item := range newQns.Items {
		//INSERT IGNORE ensures that the same question won't be added again
		stmt, err := db.Prepare("INSERT IGNORE INTO questions(question_id, question_title, question_URL, body, creation_date) VALUES (?, ?, ?, ?, ?)")
		if err != nil {
			return err
		}
		_, err = stmt.Exec(item.Question_id, html.UnescapeString(item.Title), item.Link, html.UnescapeString(StripTags(item.Body)), item.Creation_date)
		if err != nil {
			log.Println("Exec insertion for question failed!:\t", err)
			continue
		}

		for _, tag := range item.Tags {
			stmt, err = db.Prepare("INSERT IGNORE INTO question_tag(question_id, tag) VALUES(?, ?)")
			if err != nil {
				log.Println("question_tag insertion failed!:\t", err)
				continue
			}

			_, err = stmt.Exec(item.Question_id, tag)
			if err != nil {
				log.Println("Exec insertion for question_tag failed!:\t", err)
				continue
			}
		}
	}
	return nil
}
Пример #6
0
func Google(searchTerm string, results int) GoogleResult {
	var resp GoogleResult
	var uri string = fmt.Sprintf("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=%d&q=%s",
		results, url.QueryEscape(searchTerm))
	body, err := Get(&uri)
	if err != "" {
		resp.Error = err
		return resp
	}
	errr := json.Unmarshal(body, &resp)
	if errr != nil {
		resp.Error = errr.Error()
		return resp
	}
	if len(resp.Results.Data) == 0 {
		resp.Error = fmt.Sprintf("Google couldn't find \"%s\"", searchTerm)
		return resp
	}
	for i, _ := range resp.Results.Data {
		if resp.Results.Data[i].Title != "" {
			resp.Results.Data[i].Title = html.UnescapeString(resp.Results.Data[i].Title)
		}
		if resp.Results.Data[i].Content != "" {
			resp.Results.Data[i].Content = html.UnescapeString(resp.Results.Data[i].Content)
		}
	}
	return resp
}
Пример #7
0
// Message returns the message content for this message.
func (m *LiveChatMessage) Message() string {
	switch m.Snippet.Type {
	case LiveChatMessageSnippetTypeText:
		return html.UnescapeString(m.Snippet.TextMessageDetails.MessageText)
	}
	return html.UnescapeString(m.Snippet.DisplayMessage)
}
Пример #8
0
func parseRSS(rss []byte, source string) (map[string]MangaEntry, error) {
	src := strings.Split(lib.Sanitise(string(rss[bytes.Index(rss, []byte("<item>")):])), "</item>")
	src = src[0 : len(src)-1]
	entries := map[string]MangaEntry{}
	var title, tmpDate string
	for _, line := range src {
		if line == "" {
			continue
		}
		title = line[strings.Index(line, "<title>")+7 : strings.Index(line, "</title>")]
		title = html.UnescapeString(title)
		if source == "mangafox" {
			title = html.UnescapeString(title) // one more time - mangafox double escape sometimes -.-
		}
		tmpDate = line[strings.Index(line, "<pubDate>")+9 : strings.Index(line, "</pubDate>")]
		date, err := time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", tmpDate)
		if err != nil {
			logger.Error(err.Error())
			return nil, errors.New("parseRSS failed to parse time : " + tmpDate)
		}
		entries[strings.ToLower(title)] = MangaEntry{
			Title: title,
			Link:  line[strings.Index(line, "<link>")+6 : strings.Index(line, "</link>")],
			Date:  date.Unix(),
			Desc:  line[strings.Index(line, "<description>")+13 : strings.Index(line, "</description>")],
		}
	}
	return entries, nil
}
Пример #9
0
// Sends a message show the players the question card.
func (bot *CAHBot) DisplayQuestionCard(GameID string, AddCardsToPlayersHands bool) {
	log.Printf("Getting question card index for game with id %v", GameID)
	tx, err := bot.db_conn.Begin()
	defer tx.Rollback()
	if err != nil {
		log.Printf("ERROR: %v", err)
		return
	}
	var index int
	err = tx.QueryRow("SELECT get_question_card($1)", GameID).Scan(&index)
	if err != nil {
		log.Printf("ERROR: %v", err)
		return
	}
	log.Printf("The current question cards for game with id %v has index %v.", GameID, index)
	if AddCardsToPlayersHands && bot.AllQuestionCards[index].NumAnswers > 1 {
		_, err = tx.Exec("SELECT add_cards_to_all_in_game($1, $2)", GameID, bot.AllQuestionCards[index].NumAnswers-1)
		if err != nil {
			log.Printf("ERROR: %v", err)
			return
		}
	}
	tx.Commit()
	log.Printf("Sending question card to game with ID %v...", GameID)
	var message string = "Here is the question card:\n\n"
	message += strings.Replace(html.UnescapeString(bot.AllQuestionCards[index].Text), "\\\"", "", -1)
	bot.SendMessageToGame(GameID, html.UnescapeString(message))
}
Пример #10
0
func (presenter EntryPresenter) FormattedExcerpt() template.HTML {
	unescaped := html.UnescapeString(presenter.Excerpt)
	p := bluemonday.UGCPolicy()
	sanitized := p.Sanitize(unescaped)
	unescaped = html.UnescapeString(sanitized)
	return template.HTML(unescaped)
}
Пример #11
0
// This method lists the answers for everyone and allows the czar to choose one.
func (bot *CAHBot) ListAnswers(GameID string) {
	tx, err := bot.db_conn.Begin()
	defer tx.Rollback()
	if err != nil {
		log.Printf("ERROR: %v", err)
		return
	}
	var cards string
	err = tx.QueryRow("SELECT get_answers($1)", GameID).Scan(&cards)
	if err != nil {
		log.Printf("ERROR: %v", err)
		return
	}
	text := "Here are the submitted answers:\n\n"
	cardsKeyboard := make([][]string, 1)
	for i, val := range ShuffleAnswers(strings.Split(cards[1:len(cards)-1], "+=+\",")) {
		text += strings.Replace(html.UnescapeString(strings.Replace(val[1:len(val)-1], "+=+", "", -1)), "\\\"", "", -1) + "\n"
		cardsKeyboard[i] = make([]string, 1)
		cardsKeyboard[i][0] = strings.Replace(html.UnescapeString(strings.Replace(val[1:len(val)-1], "+=+", "", -1)), "\\\"", "", -1)
	}
	log.Printf("Showing everyone the answers submitted for game %v.", GameID)
	bot.SendMessageToGame(GameID, text)
	var czarID int
	err = tx.QueryRow("SELECT czar_id($1, $2)", GameID, "czarbest").Scan(&czarID)
	if err != nil {
		log.Printf("ERROR: %v", err)
		return
	}
	tx.Commit()
	log.Printf("Asking the czar, %v, to pick an answer for game with id %v.", czarID, GameID)
	message := tgbotapi.NewMessage(czarID, "Czar, please choose the best answer.")
	message.ReplyMarkup = tgbotapi.ReplyKeyboardMarkup{cardsKeyboard, true, true, false}
	bot.SendMessage(message)
}
Пример #12
0
func Last(user string) (string, error) {
	brl := "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&api_key=37c444dd2fb14904cca0bce2999e4a81&user="******"", nil
	}
	defer r.Body.Close()

	b, x := ioutil.ReadAll(r.Body)
	if x != nil {
		return "", nil
	}
	if b == nil {
		return "", nil
	}
	buf := string(b)
	re := regexp.MustCompile("<name>.*?</name>")
	title := re.FindString(buf)
	re = regexp.MustCompile("<artist.*?\">.*?</artist>")
	artist := re.FindString(buf)
	re = regexp.MustCompile("<.*?>")
	artist = re.ReplaceAllLiteralString(artist, "")
	artist = html.UnescapeString(artist)
	title = re.ReplaceAllLiteralString(title, "")
	title = html.UnescapeString(title)

	if title != "" && artist != "" {
		return (artist + " - " + title), nil
	}
	return "", nil
}
Пример #13
0
func (m *Module) notify(client *irc.Client, post post) {
	ftitle := html.UnescapeString(post.Feed.Title)
	for _, ch := range client.Channels {
		ititle := html.UnescapeString(post.Item.Title)
		client.Write("NOTICE %s :%s -- %s new entry %s: %s",
			ch, strings.ToUpper(m.Name()), ftitle, ititle, post.Item.Link)
	}
}
Пример #14
0
func (t *Text) ToString() string {
	switch t.Type {
	case "text":
		return html.UnescapeString(t.Body)
	case "html":
		return html.UnescapeString(sanitizer.StripTags(t.Body))
	}
	return t.Body
}
Пример #15
0
// MergeAndSendEmail creates both parts of an email from database stored
// templates and then merges the metadata and sends them.
func MergeAndSendEmail(
	siteID int64,
	from string,
	to string,
	subjectTemplate *template.Template,
	textTemplate *template.Template,
	htmlTemplate *template.Template,
	data interface{},
) (int, error) {
	// If we are not prod environment we really never want to send emails
	// by accident as we may be spamming people if the database hasn't been
	// sanitised (which it shoud). This is by whitelist, if this isn't the
	// production environment then only @microcosm.cc recipients will
	// get the email.
	//
	// If you need to test emails to specific external email hosts then you
	// will need to consciously do so by doing so outside of this code
	if conf.ConfigStrings[conf.Environment] != `prod` &&
		!strings.Contains(to, "@microcosm.cc") {

		glog.Infof("dev environment, skipping email to %s", to)
		return http.StatusOK, nil
	}

	var email = EmailType{}

	email.From = from

	email.To = to

	var emailSubject bytes.Buffer
	err := subjectTemplate.Execute(&emailSubject, data)
	if err != nil {
		glog.Errorf("%s %+v", "subjectTemplate.Execute()", err)
		return http.StatusInternalServerError, err
	}
	email.Subject = html.UnescapeString(emailSubject.String())

	var emailText bytes.Buffer
	err = textTemplate.Execute(&emailText, data)
	if err != nil {
		glog.Errorf("%s %+v", "textTemplate.Execute()", err)
		return http.StatusInternalServerError, err
	}
	email.BodyText = html.UnescapeString(emailText.String())

	var emailHTML bytes.Buffer
	err = htmlTemplate.Execute(&emailHTML, data)
	if err != nil {
		glog.Errorf("%s %+v", "htmlTemplate.Execute()", err)
		return http.StatusInternalServerError, err
	}
	email.BodyHTML = emailHTML.String()

	return email.Send(siteID)
}
Пример #16
0
// Escapes html that hasn't already been escaped
func EscapeOnce(input interface{}, data map[string]interface{}) interface{} {
	switch typed := input.(type) {
	case string:
		return html.EscapeString(html.UnescapeString(typed))
	case []byte:
		return html.EscapeString(html.UnescapeString(string(typed)))
	default:
		return input
	}
}
Пример #17
0
func prepareArticle(data data.Article) (string, indexArticle) {
	ia := indexArticle{FeedId: strconv.FormatInt(int64(data.FeedId), 10),
		ArticleId:   strconv.FormatInt(int64(data.Id), 10),
		Title:       html.UnescapeString(StripTags(data.Title)),
		Description: html.UnescapeString(StripTags(data.Description)),
		Link:        data.Link, Date: data.Date,
	}

	return strconv.FormatInt(int64(data.Id), 10), ia
}
Пример #18
0
func (s *Scraper) ParseTags(r io.Reader, webUrl string) (wildcard.Wildcard, error) {
	doc, err := goquery.NewDocumentFromReader(r)
	if err != nil {
		return nil, err
	}
	results := make(map[string]string)
	// First we deal with a couple special tags to get the title
	// and the favicon
	title := doc.Find("title").Text()
	if title != "" {
		results["title"] = html.UnescapeString(title)
	}
	favicon, ok := doc.Find("link[rel~=icon]").Attr("href")
	if ok {
		faviconUrl, err := url.Parse(favicon)
		if err == nil {
			if faviconUrl.Scheme == "" {
				faviconUrl.Scheme = "http"
			}
			if faviconUrl.Host == "" {
				u, _ := url.Parse(webUrl)
				faviconUrl.Host = u.Host
			}
			results["favicon"] = faviconUrl.String()
		}
	}
	// Find all meta tags for all different og prefixes we support
	tags := doc.Find(`meta[name="description"]`)
	for _, metaTag := range rawMetaTags {
		tags = tags.Add(fmt.Sprintf(`meta[name="%s"]`, metaTag))
	}
	for _, prefix := range ogPrefixes {
		tags = tags.Add(fmt.Sprintf(`meta[property^="%s:"]`, prefix))
		tags = tags.Add(fmt.Sprintf(`meta[name^="%s:"]`, prefix))
	}
	// For all the tags, extract the content
	tags.Each(func(i int, selection *goquery.Selection) {
		key, ok := selection.Attr("name")
		if !ok {
			key, _ = selection.Attr("property")
		}
		content, _ := selection.Attr("content")
		// Open graph defers to the first tag that we understand.
		_, alreadySet := results[key]
		if !alreadySet {
			results[key] = html.UnescapeString(content)
		}
	})
	card, err := convertTagsToCard(results, webUrl)
	if err != nil {
		return nil, err
	}
	return card, nil
}
Пример #19
0
func phyElements(w http.ResponseWriter, r *http.Request) {
	dest := ""
	if r.FormValue("dest") == "" && len(utils.SplitPath(html.UnescapeString(r.FormValue("path")))) > 0 {
		// go up one directory
		dest = filepath.Dir(html.UnescapeString(r.FormValue("path")))
	} else {
		dest = filepath.Join(html.UnescapeString(r.FormValue("path")), html.UnescapeString(r.FormValue("dest")))
	}

	level := len(utils.SplitPath(dest))
	var data []byte
	var elements []element

	if level == 0 {
		elements = make([]element, len(repos))
		for i, e := range repos {
			elements[i] = element{e.Name, "DIR", "0", "0", true, dest}
		}
	} else if level > 0 {
		fp := filepath.Join("repositories", utils.SplitPath(dest)[0], "origin")
		if level > 1 {
			for _, e := range utils.SplitPath(dest)[1:] {
				fp = filepath.Join(fp, e)
			}
		}
		infos, err := ioutil.ReadDir(fp)
		if err != nil && !os.IsNotExist(err) {
			log.Panic(err)
		}
		if err == nil {
			elements = make([]element, len(infos))
			for i, e := range infos {
				ext := filepath.Ext(e.Name())
				if e.IsDir() {
					ext = "DIR"
				}
				elements[i] = element{e.Name(), ext, strconv.FormatInt(e.Size(), 10), e.ModTime().Format(types.TIMESTAMP_FMT), e.IsDir(), dest}
			}
		}
	}

	if len(elements) == 0 {
		elements = []element{element{"", "DUMMY0", "0", "0", false, dest}}
	}

	data, err := json.Marshal(elements)
	if err != nil {
		log.Panic(err)
	}

	w.Write(data)
}
Пример #20
0
// name splits track's title to artist and title if there is one of separators
// in there and unescape them.
// E.g. if track has title "Michael Jackson - Thriller" then this function will
// return as first string "Michael Jackson" and as second string "Thriller".
func (t Track) name() (string, string) {
	artist := html.UnescapeString(strings.TrimSpace(t.JArtist))
	title := html.UnescapeString(strings.TrimSpace(t.JTitle))
	separators := [...]string{" - ", " ~ ", " – "}
	for _, sep := range separators {
		if strings.Contains(t.JTitle, sep) {
			splitted := strings.SplitN(t.JTitle, sep, 2)
			artist = splitted[0]
			title = splitted[1]
		}
	}
	return artist, title
}
Пример #21
0
func Fuzz(data []byte) int {
	s0 := string(data)
	s1 := html.EscapeString(s0)
	s2 := html.UnescapeString(s1)
	if s0 != s2 {
		fmt.Printf("s0: %q\n", s0)
		fmt.Printf("s1: %q\n", s1)
		fmt.Printf("s2: %q\n", s2)
		panic("string changed")
	}
	s3 := html.UnescapeString(s0)
	html.EscapeString(s3)
	return 0
}
Пример #22
0
func (this *DataAccessLayer) FindUserByName(name string) (*User, error) {
	row := this.db.QueryRow("SELECT id, name, password, email FROM users WHERE name='" + name + "'")
	user := User{}
	err := row.Scan(&user.UserId, &user.UserName, &user.Password, &user.Email)
	switch {
	case err == sql.ErrNoRows:
		return nil, nil
	case err != nil:
		return nil, err
	}
	user.UserName = html.UnescapeString(user.UserName)
	user.Email = html.UnescapeString(user.Email)
	return &user, nil
}
Пример #23
0
func ExtractExtraName(node *h5.Node) string {
	if node.Children[1].Children[0].Type == 0 {
		return strings.Trim(html.UnescapeString(node.Children[1].Children[0].Data()), ": ")
	}

	return ""
}
Пример #24
0
// SendToIrc sends the message passed to it
// to the currently connected irc server in the currently
// joined channel as the configured user
func SendToIrc(m common.Message) {
	go func(m common.Message) {
		msg := fmt.Sprintf("%s: %s", m.Username, m.Text)
		Log(fmt.Sprintf("sending: %s", msg))
		ircClient.Privmsg(ircChannel, html.UnescapeString(msg))
	}(m)
}
Пример #25
0
func main() {
	buf, _ := ioutil.ReadFile("E:/tmp/zsyy.html")
	str := html.EscapeString(string(buf))
	//fmt.Print(string(buf))
	fmt.Println(html.UnescapeString(str))
	fmt.Println(url.QueryEscape("http://golang.org/pkg/net/url/"))
	urls, err := url.QueryUnescape("http://golang.org/pkg/net/url/")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(urls)
	uparse, err := url.Parse("http://180.153.244.220/gxtime.svn/gxtsdk")
	if err != nil {
		fmt.Println("err", err)
	}
	q := uparse.Query()
	q.Add("name", "whj")
	q.Add("pwd", "wanghaijun")
	uparse.RawQuery = q.Encode()
	fmt.Println(uparse.Host, uparse.Path)
	fmt.Println(uparse, uparse.RequestURI(), uparse.RawQuery)
	testp := TestPrint{Str: "1111", Int: 12}
	fmt.Println(&testp)
	char := make([]byte, 100, 200)
	fmt.Println(cap(char), len(char))
}
Пример #26
0
func SendMail(to, subject, body string) *model.AppError {

	if len(Cfg.EmailSettings.SMTPServer) == 0 || Cfg.EmailSettings.ByPassEmail {
		return nil
	}

	fromMail := mail.Address{Cfg.EmailSettings.FeedbackName, Cfg.EmailSettings.FeedbackEmail}
	toMail := mail.Address{"", to}

	headers := make(map[string]string)
	headers["From"] = fromMail.String()
	headers["To"] = toMail.String()
	headers["Subject"] = html.UnescapeString(subject)
	headers["MIME-version"] = "1.0"
	headers["Content-Type"] = "text/html"

	message := ""
	for k, v := range headers {
		message += fmt.Sprintf("%s: %s\r\n", k, v)
	}
	message += "\r\n<html><body>" + body + "</body></html>"

	conn, err1 := connectToSMTPServer()
	if err1 != nil {
		return err1
	}
	defer conn.Close()

	c, err2 := newSMTPClient(conn)
	if err2 != nil {
		return err2
	}
	defer c.Quit()
	defer c.Close()

	if err := c.Mail(fromMail.Address); err != nil {
		return model.NewAppError("SendMail", "Failed to add from email address", err.Error())
	}

	if err := c.Rcpt(toMail.Address); err != nil {
		return model.NewAppError("SendMail", "Failed to add to email address", err.Error())
	}

	w, err := c.Data()
	if err != nil {
		return model.NewAppError("SendMail", "Failed to add email messsage data", err.Error())
	}

	_, err = w.Write([]byte(message))
	if err != nil {
		return model.NewAppError("SendMail", "Failed to write email message", err.Error())
	}

	err = w.Close()
	if err != nil {
		return model.NewAppError("SendMail", "Failed to close connection to SMTP server", err.Error())
	}

	return nil
}
Пример #27
0
func main() {
	limitFl := flag.Int64("limit", 10240, "Page read size limit")
	flag.Parse()

	for _, urlStr := range os.Args[1:] {
		resp, err := http.Get(urlStr)
		if err != nil {
			log.Fatal("cannot GET url", "url", urlStr, "error", err.Error())
		}
		defer resp.Body.Close()

		b, err := ioutil.ReadAll(io.LimitReader(resp.Body, *limitFl))
		if err != nil {
			log.Fatal("cannot read HTTP response", "url", urlStr, "error", err.Error())
		}

		s := html.UnescapeString(string(b))
		doc, err := readability.NewDocument(s)
		if err != nil {
			log.Fatal("cannot parse page", "error", err.Error())
		}

		fmt.Println(doc.Content())
	}
}
Пример #28
0
func htmlUnescape(in interface{}) (string, error) {
	conv, err := cast.ToStringE(in)
	if err != nil {
		return "", err
	}
	return html.UnescapeString(conv), nil
}
Пример #29
0
// ValidateInput checks the data input for correctness
func (m *UpdateTagModel) ValidateInput() (err error) {
	if m.Ib == 0 {
		return e.ErrInvalidParam
	}

	if m.TagType == 0 {
		return e.ErrInvalidParam
	}

	// Initialize bluemonday
	p := bluemonday.StrictPolicy()

	// sanitize for html and xss
	m.Tag = html.UnescapeString(p.Sanitize(m.Tag))

	// Validate name input
	tag := validate.Validate{Input: m.Tag, Max: config.Settings.Limits.TagMaxLength, Min: config.Settings.Limits.TagMinLength}
	if tag.IsEmpty() {
		return e.ErrNoTagName
	} else if tag.MinPartsLength() {
		return e.ErrTagShort
	} else if tag.MaxLength() {
		return e.ErrTagLong
	}

	return

}
Пример #30
0
func ExtractDetail(node *h5.Node) (key, val string) {
	query := transform.NewSelectorQuery(".product_feature_name")

	result := query.Apply(node)

	key = strings.Trim(html.UnescapeString(result[0].Children[0].Data()), " :\t\n\r")

	query = transform.NewSelectorQuery(".product_feature_value")

	result = query.Apply(node)

	val = html.UnescapeString(result[0].Children[0].Data())
	val = strings.Trim(val, " :\t\n\r")

	return
}