<commit_before>'use strict';

var http = require('http'),
    util = require('util'),
    fs = require('fs'),
    forms = require('forms'),
    jsontemplate = require('./json-template');

const dns = require('dns');

var fields = forms.fields,
    validators = forms.validators;

// template for the example page
var template = jsontemplate.Template(
    fs.readFileSync(__dirname + '/page.jsont').toString()
);

// our example registration form
var reg_form = forms.create({
    url: fields.string({ required: true }),
});

http.createServer(function (req, res) {
    reg_form.handle(req, {
        success: function (form) {
            res.writeHead(200, { 'Content-Type': 'text/html' });
            var url = form.data['url'].toString('utf-8').trim()
            dns.lookup(url, (err, address, family) => {
              if (err) {
                res.end(`<h1>Error occured for domain ${url}:  ${err.toString()}</h1>`)
              } else {
                res.end(`<h1>IP Address for domain ${url} is ${address}</h1>`);
              }
            });
        },
        // perhaps also have error and empty events
        other: function (form) {
            res.writeHead(200, { 'Content-Type': 'text/html' });
            res.end(template.expand({
                form: form.toHTML(),
                enctype: '',
                method: 'GET'
            }));
        }
    });

}).listen(8080);
<commit_msg>fix html escaping<commit_after>'use strict';

var http = require('http'),
    util = require('util'),
    fs = require('fs'),
    forms = require('forms'),
    Entities = require('html-entities').AllHtmlEntities,
    jsontemplate = require('./json-template');

const entities = new Entities();
const dns = require('dns');

var fields = forms.fields,
    validators = forms.validators;

// template for the example page
var template = jsontemplate.Template(
    fs.readFileSync(__dirname + '/page.jsont').toString()
);

// our example registration form
var reg_form = forms.create({
    url: fields.string({ required: true }),
});

http.createServer(function (req, res) {
    reg_form.handle(req, {
        success: function (form) {
            res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
            // convert uri escaping. %26%2345815 => &#45815;
            var url = decodeURIComponent(form.data['url'].toString('utf-8').trim())
            // decode html escaping &#45815; => 닷
            var utf8URL = entities.decode(url)
            dns.lookup(utf8URL, (err, address, family) => {
              if (err) {
                res.end(`<h1>Error occured for domain ${utf8URL}:  ${err.toString()}</h1>`)
              } else {
                res.end(`<h1>IP Address for domain ${utf8URL} is ${address}</h1>`);
              }
            });
        },
        // perhaps also have error and empty events
        other: function (form) {
            res.writeHead(200, { 'Content-Type': 'text/html' });
            res.end(template.expand({
                form: form.toHTML(),
                enctype: '',
                method: 'GET'
            }));
        }
    });

}).listen(8080);

{'fraction_non_alphanumeric': 0.16374641605606882, 'fraction_numerical': 0.017202930869703727, 'mean_word_length': 2.1243781094527363, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '279707', 'n_tokens_mistral': 951, 'n_tokens_neox': 920, 'n_words': 212}