Is there anything that provides the kind of support PHP's filter_var does in ColdFusion? - security

I've found filter_var to be extremely useful in validating and sanitizing user input with PHP, but I've yet to find anything even remotely as convenient in ColdFusion (more specifically, CF8).
Obviously I can hack together something using REReplace, but that would take significantly more time to code up and would be much uglier than using the pre-defined filters available in PHP. Is there a more efficient way or do I just need to bite the bullet?

There are three different options available to you. Since you're attempting to manage user input, I assume you're using forms. isValid most closely mimics your functionality, allowing you to check if a value specified matches either a data type or a regular expression and returns true or false, and includes attributes by default to define a range. It does not support the ability to create a custom 'filter' beyond defining a regular expression however.
The second option would be using cfparam tags on your POST processing page, which allows you to specify the existance of a variable, test against a data type or define a regular expression, and optionally assign a default value if the variable doesn't exist. If you attempt to process a page where the field is not defined and no default value is assigned however, ColdFusion throws an error.
Finally, you can do validation by using cfform and cfinput fields on your form itself; which allows for client-side data validation for existence and types (it also supports server-side validation but it's implementation is sloppy), regular expressions, and input masking: taking user-inputted data and conforming it to a specific format (like adding dashes to phone numbers and zip codes).

Related

Value Objects with third party validation

I need some help...
Value objects, by definition, are immutable data classes that only use other value objects or primitives. And an value object only should be created with a valid value.
But... what happens when to construct a valid value object we need to validate the data using a third party library?
For example a Phone and a Mobile value objects. Build a valid phone depends on a country and the validation rules could constantly change and be complex. We don't want to spend time changing phone validation rules because this is not the core of the our business... so we want to validate the data using Google libphone library.
Possible solutions:
Inject the third party library by construct: new Phone($phone, $validator)
Inject the third party library by factory method: Phone::fromString($phone, $validator)
Build the object from a class factory.
First and second options I guess is not the correct way, Value objects don't necessarily need collaborators...
Third option allows to create invalid phones if you instantiate the phone outside the factory.
Any idea?
Thanks.
The solution for this is to have 2 types UnvalidatedPhone and ValidatedPhone (both part of the domain), together with your 3rd option.
The incoming command will have an UnvalidatedPhone and as you process the command, at some point you'll validate it using the builder/factory and get a ValidatedPhone. This is even better if you can hide the constructor of ValidatedPhone, so the validator is the only thing that can create a ValidatedPhone.
Mini warning: If you are writing this in an OO language (I guess you do), the two phone classes don't need to be part of a hierarchy. Try to keep them separate.

Can custom settings be "passed into" a Contentful UI extension assignment?

Is it possible to pass data into UI extensions assignments (meaning UI Extension X assigned to Field Y), in order to alter their functionality slightly for different situations, without having to reimplement the entire extension?
For example, CodeMirror is a really neat embedded editor, but it has a bunch of "modes," depending on what language you're working with. If we could even pass in a string to represent the desired mode when the extension is assigned to a field, that would remove the need to do a different extension just to use different syntax highlighting.
With this, there could now be a generic "CodeMirror Editor" UI extension which is then just configured a runtime.
On the other end of the extreme, we could specify entire JSON objects when the extension is assigned to a field, to further specify configuration options.
This would make UI extensions so much more...useful. Does this functionality exist now, or is there some way to reasonably make it work? Is there some place on the field specification where I can "park" a JSON string, then access it from inside the extension?
Contentful has launched something called "Configuration parameters" for UI extensions that could be used to solve this issue.
They have two types of parameters, installation and instance parameters. Installation parameters are set when installing the UI extension, and instance parameters are set when configuring a field on a content type to use the extension. The latter would be perfect for your use case.
To use this feature you need to:
Create a parameter definition for the UI extension in the extension.json file. E.g. a new instance parameter called "codeMirrorSettings" of type Symbol with name "CodeMirror Settings".
Within the extension, fetch the current parameters using extensionsApi.parameters.instance.codeMirrorSettings.
Documentation for configuration parameters can be found in Contentful's docs:
https://www.contentful.com/developers/docs/references/content-management-api/#/reference/ui-extensions/configuration-parameters
https://github.com/contentful/ui-extensions-sdk/blob/master/docs/ui-extensions-sdk-frontend.md#extensionparameters
What you could do is just read this setting from another field, be that a string or a json object.
For example the slug generator automatically generates its value from the title field.
You could perhaps do something like this:
const cfExt = window.contentfulExtension || window.contentfulWidget
cfExt.init(api => {
var langField = api.entry.fields.mirrorLang || 'default'
//Rest of implementation
})
Well, I wrote something for this, specific to my situation, but generalizable to others. This is an example if a UI extension that retrieves settings from another entry in the space, and uses it to dynamically configure itself.
https://github.com/deanebarker/contentful-code-editor

management of big number of parameters of a keyword in VBscript

I'm working on test automation using keyword driven framework. I have to add a keyword add_car. This keyword needs a big number of parameters that should be entered in the excel sheet as parameters for this keyword.
I want to find a solution to manage the big number of parameters(some of them are always required and the others are optional)
The below picture is an example of how the values of parameters are entered in the Excel sheet.
excel sheet example
Here is how I call this keyword in UFT
keyword Call in UFT
And in my Functions Library, I defined the instructions of my_keyword.
Is there any solution to manage this big number of parameters(I have more than 30 parameter in general some are optional and others are always required).
I'd advise walking through your worksheet to get all parameters and store them into a dictionary. Then you would call your functions by calling the dictionary instead of all parameters individually.
The way to manage all of the parameters to add them into dictionary would have to be handled in a separate function and you could then check if the parameters exist/have values inside your functions or even externally. It would actually be kind of a whole new framework just to work with it, but when you're done, you could reuse the functions anywhere you wanted.
At least that was the way implemented in the project I've worked (though I was not the one to implement it).
It is hard to provide a thorough answer about the topic because it is pretty extensive, but for starters, I'd recommend this link about working with dictionaries:
http://automated-360.com/qtpuft/advanced-concepts/everything-dictionary-object/
In a very brief way, Dictionary objects are sort of a collection of Key,Item pairs, where you could store your parameters like Parameter1,ParameterValue to use later.
It also allows you to sort your parameters, check for existence, store them in a Case Insensitive way, edit them, delete them and so forth.
This is what I can offer to you now.
Happy research and happy coding.
Not sure how many parameters do you have.
However, I have 600+ parameters required for 1 test case (I know... It's a huge end to end test that takes loads of parameters).
I have used different tabs in excel sheet to logically separate the test data parameters.
I read the excel as database (using ADODB.connection) and query each tab in excel to get the row that I need. I can write SQL join to query from multiple excel tabs at once.
Reference on reading excel as DB:
http://www.automation.ultimatetimepass.com/index.php/home/qtp/excel/qtp-read-excel-using-adodb-connection/10-qtp-excel
Few thoughts on this.
Possible solution 1: Text File Approach
You will have all the parameters are stored with key,value combination like given below in the text file.
Parameter1=abc
Parameter2=def
Parameter3=ghi
The advantage here is when any of your parameter not needed, just remove from the text file.That being said, Your framework engine should read the keyword "ReadFile" as function and return a collection of string from file.
sParameterList = ReadFile("")
Possible solution 2:
Define all the parameters with comma separated value.Split and pass it your function call.
Parameter1=abc,Parameter2=def,Parameter3=ghi

Expression Engine - passing multiple categories as URL segments

I'm trying to create a product filter with deep-linking capability. Essentially, I want the user to be able to filter my product list on multiple categories and have the URL reflect the filtering they've done.
So it would start as:
www.site.com/products/
My first level of category filtering already works. So I can use EE's regular handling of URL segments to get to my first level of filtering. For instance:
www.site.com/products/leatherthongs
Returns a filtered subset showing only a spectacular collection of leather thongs. But now I want the user to be able to filter on another category - color for instance. This is where stuff stops working.
EE's way of handling multiple categories inside templates (with ampersands or pipes) doesn't work in the URL:
www.site.com/products/leatherthongs&red
Nor does any variation that I've tried.
My next move is to create a simple raw PHP method that can capture regular querystring parameters and then inject them into the {entries} tag before rendering. Not very difficult, but quite ugly. I would love to know if there is a way to handle multiple categories in the URL natively.
Thanks for your time.
Have you considered using Low's Seg2Cat add-on? I'm not sure how complex you want to make this but it seems that you could specify something in your channel:entries loop like categories='{segment_2){if segment_3}|{segment_3_category_id}{/if}'
This exact syntax is untested but I have had success in the past with a similar solution.

How to import two cc both contain compositeData?

I do not know that the question is right? Please do not take it your mind if it is crazy. Actually I am working on xpages application. There I need to do two things, that I want to add the picklist functionality and binding the dynamic data like field_1,field_2,field_3, ... upto n depands on customer choice.I am using the composite data for both custom controls. I can remove the picklist control's composite data and also I can do it by passing the scope variables. But that takes more time than the composite data.
I did not get any error. But the binded documents is not saving.
Is it possible to import the CCs that are having composite Data?
Code for first CC:-
<xc:viewpicklist datasrc="view1" dialogID="dialog1" dialogWidth="700px" dialogTitle="Pick this field value!!!">
<xc:this.viewColumn>
<xp:value>0</xp:value>
<xp:value>1</xp:value>
<xp:value>2</xp:value>
</xc:this.viewColumn>
</xc:viewpicklist>
Code for Second CC:-
<xc:BOM_Partinfo BOM_Partinfo="#{document1}"
TNUM="field#{index+1}" Desc="Desc#{index+1}" quan="Ea#{index+1}"
exp="exp#{index+1}" cap="cap#{index+1}" total="price#{index+1}"
RD="RD#{index+1}" m="manufact#{index+1}"
m_n="manufactnum#{index+1}">
</xc:BOM_Partinfo>
You can read information that is set in the properties of a custom control if it was static in the calling page:
var x = getComponent("yourcomponentid");
x.getPropertyMap().get("parametername");
but you want to propagate a data source from the outer control to the inner control...
You need to plan carefully. If you hand over the data source, then your custom control is dependent on a fixed set of fields in the data source (that would be a parameter of type com.ibm.xsp.model.DocumentDataSource). This would violate the encapsulation principles. So I would recommend you actually hand over data bindings - the advantage: you are very flexible what to bind to (not only data sources, but also beans and scope variables would work then). The trick is you provide the binding name as you would statically type it in (e.g. "document1.subject" or "requestScope.bla" ). In your control you then do
${"#{compositeData.field1}"}
${"#{compositeData.field2}"}
You need one for each field.
You cannot send a document data source to a custom control using composite data parameters.
You can try and use this script instead
http://openntf.org/XSnippets.nsf/snippet.xsp?id=access-datasources-of-custom-controls
Define data source in XP/CC where you want those CCs. Define parameter "dataSourceName" for both CCs. Inside each of them use EL "requestScope[compositeData.dataSourceName].fieldName" everywhere you want to bind to datasource.

Resources