faker-ruby / faker

A library for generating fake data such as names, addresses, and phone numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML generator

ruban-thilak opened this issue · comments

Is your feature request related to a problem? Please describe it.

The problem is related to testing HTML sanitization in a Rails application. Currently, there is a need for a new HTML generator that can generate HTML code with various elements and attributes to test the effectiveness of the HTML sanitization process. This will help identify any potential vulnerabilities or issues in the sanitization implementation.

If you're adding new objects, please describe how you would use them.

The proposed HTML generator can be used in test suites to generate HTML code with different elements and attributes. This will allow developers to test the effectiveness of the HTML sanitization process in the Rails application. Here's an example of how the generator could be used in a test case:

# Example test case using the HTML generator
require 'rails_helper'

RSpec.describe 'HTML sanitization' do
  it 'sanitizes user-generated HTML' do
    input_html = Faker::HTML.random # Generate HTML code using the new generator
    sanitized_html = sanitize_html(input_html) # Call the HTML sanitization method

    # Assert that the sanitized HTML does not contain any potentially harmful elements or attributes
    expect(sanitized_html).not_to include('<script>')
    expect(sanitized_html).not_to include('onclick')
  end
end

This way, the new HTML generator will allow developers to simulate different scenarios and ensure that the HTML sanitization process is working as expected.

Describe alternatives you've considered

One alternative would be manually creating HTML test cases with different elements and attributes. However, this approach can be time-consuming and error-prone, especially when dealing with a large number of test cases. Having a dedicated HTML generator would automate the process and make it easier to generate a wide variety of test cases.

closed by #2769